;;5/10/12 9:00 am

;;CLOSE this file and UPDATE it BEFORE modifying it!
;;COMMIT changes *often* (and always update again before each commit)
;;workflow = update, make changes, update, commit

extensions [table]

;;human-types
breed [eggtraders eggtrader]    ;; egg traders
breed [livetraders livetrader]  ;; live poultry traders
breed [byowners byowner]        ;; backyard poultry owners (the owners move w/out poultry to other households, market, arena, etc)
                                ;;ai20120109: some byowners are fc owners
breed [farmowners farmowner]    ;; owners of large farms
breed [byduckowners byduckowner];; owners of small duck flocks/ backyard ducks
breed [fgd-owners fgd-owner]      ;; FGD owners (can move w/out ducks to households, egg cooperative, market, etc)
;;poultry-types
breed [fgds fgd]                ;; free-grazing duck flocks (FGD)
breed [bychickens bychicken]
breed [byducks byduck]
breed [farms farm]
;;inanimate-types
;breed [fgdfields fgdfield]      ;; FGD fields   ;;ai20110902 not used; are there plans to use this? chk
directed-link-breed [egg-links egg-link] ;ai20120101 why a *directed* link?
directed-link-breed [livebird-links livebird-link] ;ai20120101 why a *directed* link?
undirected-link-breed [fgd-links fgd-link]
undirected-link-breed [newroads newroad]
breed [intersections intersection]


globals ;;ai: note that although NetLogo tempts one to use many globals, you shd avoid them when possible
[ 
  ;; CONSTANTS
  N-FGD
  ;N-EGGTRADERS
  N-LIVETRADERS
  N-FGDOWNERS
  N-BYOWNERS
  N-FCOWNERS
  N-FARMOWNERS
  N-BYDUCKOWNERS
  N-BARNS
  N-PRACTICE-ARENAS
  N-MATCH-ARENAS
  N-MARKETS
  N-SLAUGHTERHOUSES
  N-COOPERATIVES
  RAI-PER-DUCK              ;; per duck daily consumption rate

  location-datafile         ;; string, filename for location data
  ;; prop-fgd-barntofield   ;; slider, controls pct of fgds in barns and on field only
  num-bychick-inf
  num-byduck-inf
  num-farm-inf

  COLOR-FALLOW
  COLOR-HARVESTED
  COLOR-GROWING

  debug
  
  runsim?                  ;; boolean for simulation control
  stop-sim-reason          :: string for diagnostics
  
                          ;; patch agentsets
  rice-fields             ;; agentset containing the patches that can belong to rice fields, which can be in 3 states
  access-fields           ;; agent set of num-fields-harvested rice-field patches; these provide field access
  roads                   ;; patch agentset containing the patches that are roads
  barns                   ;; patch agentset containing the patches that are FGD barns
  edge-patches            ;; patch agentset for the edge of the world
  agents        
  match-arenas
  practice-arenas
  markets
  slaughterhouses
  cooperatives
  out-of-subdistrict-patches
  human-types
  humans
  fcowners
  livebird-suppliers
  poultry-types
  poultry-owners
  arenas
  trader-types
  

  
  ;; influenza toggle switch will control whether influenza transmission is included or not (on or off, respectvely)
;  field-infection-prob         ;; this is the probability that an exposed flock will be infected by a rice field
  latent-period          ;; this is the length of the latent period in days
  shedding-period-duck   ;; this is the length of the shedding period in days for ducks
  shedding-period-chicken;; this is the length of the shedding period in days for chickens
  road-contam-period     ;; time that the road will stay contaminated with viable virus
  trader-contam-period   ;; time that traders will stay contaminated after contact with infectious birds
  field-contam-period    ;; time that fields will stay contaminated after infected FGD flock on there
  
  road-infect-byc-prob       ;; probability that bkyd chicken flock will be infected via infected FGD flocks passing on road
  road-infect-pen-prob       ;; probability that penned duck or farmed layer flock will be infected via infected FGD flocks passing on road
  flock-eggtrader-contam-prob ;; probability that an egg trader will be contaminated when picking up eggs from an infected premeses
  live-trader-contam-prob ;; probabiltiy that a live trader will be contaminated when picking up birds from an infected premeses
  eggtrader-flock-infect-prob ;; probability that a contaminated egg trader will cause infection of a susceptible flock he visits
  livetrader-flock-infect-prob ;; probability that a contaminated live trader will cause infection of a susceptible flock he visits
  from-visit-infect-prob      ;; probability that a visitor that goes to an infected flock will infect its susceptible flock 
  to-visit-infect-prob        ;; prob that someone from an infectious flock will infect a neighbor's flock  
  arena-fc-infect-prob         ;; probability that a FC becomes infected while at the arena
  fc-bkyd-infect-prob    ;; probability that a FC infected at the arena will infect his home flock
  field-infection-prob

  days-on-field          ;; table mapping FGD's who numbers to lists
  transmissions          ;; table mapping transmission types to daily numbers
  contaminations         ;; table mapping contamination types to daily numbers

  ;; calendar variables
  DAY-NAMES
  LIVETRADER-PICKUP-SCHEDULE  ;; list, specifies for each day of the week who will do live-bird pickup
  DAY-SCHEDULE   ;; list, specifies for each day of the week which flocks want egg pickup
  day-idx                ;; int in range 0 to 6
  day-name               ;; string, one item of DAY-NAMES (i.e., a weekday name)
  week
  livetrader-pickup-days  ;; one sub-list of LIVETRADER-PICKUP-SCHEDULE, updated by update-calendar
  eggtrader-pickup-days  ;; one sub-list of DAY-SCHEDULE, updated by update-calendar
  visit-days  ;; one sub-list of DAY-SCHEDULE, updated by update-calendar
]

newroads-own [
  roadtype 
  road-patches
]

intersections-own [
  name
  int_type
]

patches-own [
  rai                       ;;ai20110815
  field-contaminant         ;; extent of contamination in [0,1] in rice field
                            ;; state 1: harvested: These are the fields that duck flocks move to 
                            ;; state 2: growing. Ducks do not graze in these fields 
                            ;; state 3: fallow. After ducks graze in the fields, they are left until the next harvest
  field-patches             ;; an agentset of patches; ``nobody`` for all but access fields
  field-num                 ;; unique field identifier
  field-state               ;; "", "harvested", "growing", or "fallow"
  ;ai: refactor ``is-occupied`` to ``occupant``
  ;is-occupied?              ;; ab: is the field free of ducks?  ;;ai20110815 (consider ``is-target?`` for clarity)
  occupant                  ;;field is the target of occupant (who may not be physically present)
  road-contam-time
  field-contam-time
  patch-type                ;;ricefield, barn, market, practice-arena, match-arena, etc
  road-access
  pcontaminated?             ;; patches will be contaminated if next to a road with infectious ducks passing by; rice field can be contaminated
  infected-outsider-FC-here?
  my-practice-group
  practice-arena-number
]



turtles-own                 ;;ai20110902 attributes common to all types
[
  infectious?               ;; is the agent infectious?
  can-contaminate?          ;; can this agent contaminate patches if infectious?
  home-patch                ;; location of barn for each FGD flock; household and yard with backyard poultry; household and yard with fighting cocks;
                            ;; household and slaughterhouse for local traders
  egg-pickup?               ;; does the turtle have eggs picked up?    
  egg-delivery?             ;; does the turtle deliver eggs to the market?    
  onsite-trader-num         ;; number of traders that come to flock to pick up eggs
  eggs-gone?                ;; eggs have been picked up for the day
  egg-type                  ;; This can be duck, chick or both egg types
  livebirds-gone?
  livebird-selldate
]

fgds-own
[
  owner                     ;; turtle, the owner of the fgd flock
  n-ducks
  exposed?                  ;; exposed but not necessarily infected
  latent?                   ;; infected but not yet infectious
  recovered?                ;; no longer infectious
  transport-type            ;; ducks transported by walking or by truck
  target-field              ;; target is a harvested rice field (i.e., a dayfield)
  infection-time            ;; "days" since infection; Increases by one day with each tick.
  shedding-time             ;; shedding time; now is a discrete value but will be selected from prob dist (normal?)
  target-road-access
  field-only?
]

fgd-owners-own
[
  
  pickup-days               ;; days that eggs are picked up by trader
  delivery-days
  links-in
  target-cooperative
  target-market
  contaminated?
  visit-list                ;; patch agentset
  n-visit-days-per-week
  
  exposed?  
  latent?
  recovered?
  infection-time
  field-only?
  own-infected-flock?
]

bychickens-own
[
  exposed?                  ;; exposed but not necessarily infected
  latent?                   ;; infected but not yet infectious
  recovered?                ;; no longer infectious
  death?                    ;; chickens will die
  infection-time            ;; "days" since infection; Increases by one day with each tick.
  shedding-time             ;; shedding time; now is a discrete value but will be selected from prob dist (normal?)
]

byowners-own
[                         
  contaminated?
  target-visit
  visit-list   
  n-visit-days-per-week  
  own-fightingcocks?
  target-practice-arena
  target-match-arena
  links-in            
  pickup-days
  delivery-days
  practice-fight-week      ;; 0 or 1 for even or odd weeks
  practice-fight-week?
  match-fight-week?
  own-infected-flock?
  latent?
  recovered?
  infection-time
  shedding-time
  own-infected-fc?
]

farms-own
[
  exposed?                  ;; exposed but not necessarily infected
  latent?                   ;; infected but not yet infectious
  recovered?                ;; no longer infectious
  death?                    ;; chickens will die
  infection-time            ;; "days" since infection; Increases by one day with each tick.
  shedding-time             ;; shedding time; now is a discrete value but will be selected from prob dist (normal?)

]

farmowners-own
[                          
  contaminated?                
  target-visit
  visit-list   
  n-visit-days-per-week  
  links-in 
  pickup-days
  delivery-days
  target-cooperative
  target-market
  own-infected-flock?
]

byducks-own
[
  exposed?                  ;; exposed but not necessarily infected
  latent?                   ;; infected but not yet infectious
  recovered?                ;; no longer infectious
  infection-time            ;; "days" since infection; Increases by one day with each tick.
  shedding-time             ;; shedding time; now is a discrete value but will be selected from prob dist (normal?)
  byduck-type
]

byduckowners-own
[  
  contaminated?                         
  target-visit
  visit-list  
  n-visit-days-per-week  
  links-in 
  pickup-days
  delivery-days
  target-market
  own-infected-flock?
  byduck-type
]

eggtraders-own
[
  contaminated?
  target-eggfarm
  collecting?
  n-eggtrader-links
  trader-contam-time
  target-market
]


livetraders-own
[
  target-livefarm
  contaminated?
  target-slaughterhouse
  livetrader-links
  n-bird-pickup-days
  trader-contam-time
]


;;;;;;;;;;;;;;;;;;;;;;;;
;;     UTILITIES      ;;
;;;;;;;;;;;;;;;;;;;;;;;;

;; return a single draw from a binomial distribution
to-report binomial [n p] ;; written by Seth Tisue
  report length filter [? < p] n-values n [random-float 1]
end

;; return a result (value) based on the defined probabilities (#weights) of each value
;; written by Nick Bennet 2009 http://groups.yahoo.com/group/netlogo-users/message/9091 
to-report random-weighted [#values #weights]
  let selector (random-float sum #weights)
  let running-sum 0
    (foreach #values #weights [
      set running-sum (running-sum + ?2)
      if (running-sum > selector) [
        report ?1
      ]
    ])
end

;;ai: ``split`` was written by Jim Lyons (2007)
to-report split [ #string #sep ] ; #sep must be non-empty string
  let result [] ; return value
  let w length #sep
  loop ; exit when done
  [ let next-pos position #sep #string
  if not is-number? next-pos
  [ report reverse (fput #string result) ]
  set result fput (substring #string 0 next-pos) result
  set #string substring #string (next-pos + w) (length #string)
  ]
end

;;ai: use law of sines to report determine
;;    minimum distance from patch to link (no wrapping)
to-report patch-near-link? [#patch #link]
  let max-distance 1
  let eps 0.0001
  set max-distance 1 + eps
  let dist 0
  let angles (list )
  let result true
  ask #link
    [
      ask both-ends
      [
        if (patch-here != #patch)
        [
          let angle abs (subtract-headings towards #patch towards other-end)
          ifelse (angle > 90)
          [set result false]
          [
            set dist (sin angle) * distance #patch
            if (dist > max-distance) [set result false]
          ]
        ]
       ]
     ]
  report result
end

to-report random-pert [#minval #likeval #maxval]
  ;use pert params to draw from a beta distribution
  let pert-var 1. / 36
  let pert-mean (#maxval + 4 * #likeval - 5 * #minval) / (6 * (#maxval - #minval))
  let temp pert-mean * (1 - pert-mean) / pert-var
  let alpha1 pert-mean * (temp - 1)
  let alpha2 (1 - pert-mean) * (temp - 1)
  let x1 random-gamma alpha1 1
  let x2 random-gamma alpha2 1
  report (x1 / (x1 + x2)) * (#maxval - #minval) + #minval
end

;;chk hard coded numbers
to-report random-visit-int
  report (random-pert 0 1 10)
end

to export-transmissions-and-contaminations
  file-open "transmissions-and-contaminations.txt"
  let %ct behaviorspace-run-number
  ;file-print "bsnum,t-or-c,type,sum"
  foreach table:keys transmissions [
    file-print (word %ct ",transmission," ? "," (sum table:get transmissions ?))
  ]
  foreach table:keys contaminations [
    file-print (word %ct ",contamination," ? "," (sum table:get contaminations ?))
  ]
  file-close
end

;;;;;;;;;;;;;;;;;;;;;;;;
;;  SETUP PROCEDURES  ;;
;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;
;;Globals;;
;;;;;;;;;;;

to startup  ;;ai: this procedure will run automatically when the model loads
  set-default-shape byowners "person"
  set-default-shape eggtraders "car"
  set-default-shape fgds "duck"
  set-default-shape fgd-owners "person"
  set-default-shape livetraders "person"
  set-default-shape farmowners "person"
  set-default-shape byduckowners "person"
  set-default-shape livetraders "truck"
  set-default-shape farms "farm"
  set-default-shape byducks "bird side"
  set-default-shape bychickens "backyard"
end


to setup                   ;; setup the display with globals, patches, agents
  ;clear-all    ;; problem for BS
  ;clear-ticks  ;; version 5
  clear-turtles
  clear-patches
  clear-drawing
  clear-all-plots
  clear-output

  ;;preliminaries
  set debug 0    ;; set to 0 during Bahavior Space to speed runs
  if (debug > 5) [print "enter proc: setup"]
  set runsim? true          ;; set runsim? false for programmatic stop of simulation
  set stop-sim-reason ""

  ;; file for event logging (please do not delete)
  carefully [file-delete "birdflu-xxx.log"] []
  file-open "birdflu-xxx.log"
  file-print date-and-time
  file-print ""
  file-close


  ;;define agent types
  ;; this needs to be a complete list! chk
  set human-types (list eggtraders livetraders byowners farmowners byduckowners fgd-owners fcowners)
  set humans turtles with [member? breed human-types]
  ;;chk: poultry-types needs to be a complete list! it must not be an agentset (here, that wd be empty)
  set poultry-types (list fgds bychickens byducks farms)
  set trader-types (list eggtraders livetraders)
  
  setup-globals
  setup-newroads  ;;must come before setup-patches!
  setup-patches   ;;calls place-along-roads!
  setup-agents
  ask fgds [table:put days-on-field ([who] of self) (list )]  ;;initialization of table
  reset-ticks  ;;needed at the end of setup, as of version 5
  do-plots   ;chk: plot initial state
  if (debug > 5) [print "exit proc: setup"]
  initialize-locations-file
  test-setup
end

to initialize-locations-file
  ;; creates the file for the transmission locations
  ;; and records the initial locations
  let %fnum (word "000" behaviorspace-run-number)
  let %len length %fnum
  let %fname (word "locationdata" substring %fnum (%len - 3) %len ".txt")
  set location-datafile %fname
  carefully [file-delete %fname][]
  file-open %fname
  file-print "positions after setup:"
  ask turtle-set poultry-types [
    if (latent? or infectious?) [file-type "infected "]
    file-show patch-here
  ]
  file-close
end

;; Setup the enumerations
to setup-globals
  ;; set values of constants 
  set N-FGD 9                                      
  set N-FGDOWNERS 9
  set RAI-PER-DUCK 0.005   ;; median of large flock survey
  set N-LIVETRADERS 4                                 
  set N-BYOWNERS 250  
  set N-FCOWNERS 201
  set N-FARMOWNERS 9
  set N-BYDUCKOWNERS 80
  set N-BARNS 360
  set N-MATCH-ARENAS 1
  set N-PRACTICE-ARENAS 3
  set N-MARKETS 3
  set N-COOPERATIVES 1
  set N-SLAUGHTERHOUSES 3

  set num-bychick-inf 0
  set num-byduck-inf 0
  set num-farm-inf 0
  
  set field-infection-prob 100                     ;; setup the new state change parameters
  set latent-period 1
  set road-contam-period 1        ;ai: don't change this without changing the associated per-day probability!
  set field-contam-period 30
  set trader-contam-period 1 

  ;; probabilities based on expert opinion PERT distributions
  
  set arena-fc-infect-prob random-pert 38 48 57
  set fc-bkyd-infect-prob random-pert 67 83 100
  
  set access-fields nobody      ;; initialization
  set days-on-field table:make
  set transmissions table:make
  foreach ["road-flock" "after-visit" "visitor-flock" "eggtrader-flock" "livetrader-flock" "arena-fc" "fc-flock"] [      ;; is "visitor-flock" being used?
    table:put transmissions ? (list )
  ]
  set contaminations table:make
  foreach ["flock-livetrader" "flock-eggtrader" "flock-visitor" "flock-road" "flock-field"] [
    table:put contaminations ? (list )
  ]
  
  ;; calendar variables
  set DAY-NAMES ["Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"]
  set LIVETRADER-PICKUP-SCHEDULE [[3] [2] [3] [2] [1 3] [] []]
  set DAY-SCHEDULE [[3 5 7] [1 2 5 7] [3 5 7] [2 5 7] [3 5 7] [7] [7]]
  
  setup-bs-globals
end

to setup-bs-globals
  ;; workaround to allow setting in behavior space the values of some globals:
  ;; we set these values only if BS did not
  ;; NOTE: assumes (!!) BS is not setting the variable to 0!!!

  ;; PROP-FGD-BARNTOFIELD- Not needed here because is slider
  
  ;; NUM-FGD-INF- Not needed here because is slider
  
  ;; ROAD-INFECT-PEN-PROB
  ;; Do we need to add a prob for infection of other flocks when FGD pass? 
  ;; This is the most conservative expert's indirect contact estimate.
  if (road-infect-pen-prob = 0) [ set road-infect-pen-prob random-pert 0 25 40 ]        ;;NEED TO ALSO TEST WITH ZERO VALUE
  if (road-infect-pen-prob = 999) [ set road-infect-pen-prob  0 ]
  
   ;; ROAD-INFECT-BYC-PROB
  if (road-infect-byc-prob = 0) [ set road-infect-byc-prob random-pert 29 55 71 ]       ;;NEED TO ALSO TEST WITH ZERO VALUE
  if (road-infect-byc-prob = 999) [ set road-infect-byc-prob  0 ]
  
  ;;FROM-VISIT-INFECT-PROB
  ;; previous 35 42 53 summary from all 3 experts; 5 15 30 is summary from two consistent experts
  if (from-visit-infect-prob = 0) [ set from-visit-infect-prob random-pert 5 15 30 ]
  if (from-visit-infect-prob = 999) [ set from-visit-infect-prob  0 ]   
  
  ;;TO-VISIT-INFECT-PROB
  show  (word "CURRENT to-visit-infect-prob:" to-visit-infect-prob)
  if (to-visit-infect-prob = 0) [ set to-visit-infect-prob random-pert 10 20 40]
  if (to-visit-infect-prob = 999) [ set to-visit-infect-prob  0]
  show  (word "RESET to-visit-infect-prob:" to-visit-infect-prob)
  
  ;; EGGTRADER-LINKS- Not here becuase need to set manually during runs
  
  ;; FLOCK-EGGTRADER-CONTAM-PROB
  if (flock-eggtrader-contam-prob = 0) [ set flock-eggtrader-contam-prob random-pert 53 70 88]
  
  ;; EGGTRADER-FLOCK-INFECT-PROB
  if (eggtrader-flock-infect-prob = 0) [ set eggtrader-flock-infect-prob random-pert 55 70 85]
  
  ;; FLOCK-LIVETRADER-CONTAM-PROB
  if (live-trader-contam-prob = 0) [ set live-trader-contam-prob random-pert 68 83 95]
  
  ;; LIVETRADER-FLOCK-INFECT-PROB
  if (livetrader-flock-infect-prob = 0) [ set livetrader-flock-infect-prob random-pert 68 82 92]
  
  ;; CHICKEN SHEDDING PERIOD 
  if (shedding-period-chicken = 0) [ set shedding-period-chicken 4]
  
  ;; DUCK SHEDDING PERIOD 
  if (shedding-period-duck = 0) [ set shedding-period-duck 7]
  
end

;; TO USE IN BEHAVIOUR SPACE
;[ "road-infect-pen-prob" 0 ]
;[ "road-infect-byc-prob" 0 ]
;[ "from-visit-infect-prob" 5 ]
;[ "to-visit-infect-prob" 10 ]
;[ "flock-eggtrader-contam-prob" 0 ]
;[ "eggtrader-flock-infect-prob" 0 ]
;[ "live-trader-contam-prob" 0 ]
;[ "livetrader-flock-infect-prob" 0 ]
;[ "shedding-period-chicken" 0 ]
;[ "shedding-period-duck" 0 ]

;;;;;;;;;
;Patches;
;;;;;;;;;

to setup-newroads
  let nodes table:make  ;;
  file-open "intersections.txt"
  while [not file-at-end?]
  [
    let data file-read-line
    if not (first data = "#")
    [
      set data split data " "
      ;; cast the co-ordinates from strings to numbers
      let x read-from-string item 0 data
      let y read-from-string item 1 data
      ;; get the intersection name and intersection type
      let iname item 2 data
      let itype last data
      let ilocation list (item 0 data) (item 1 data)
      ask patch x y [
        sprout-intersections 1 [
          setxy x y
          table:put nodes iname self  ;;map name to intersection (node)
          set color black
          set shape "target"
          set size 0.5
          set label (word who "(" iname ")")
        ]
      ]
      ask intersections [set home-patch patch-here ]
    ]
  ]
  file-close
  print nodes
  file-open "roads.txt"
  while [not file-at-end?]
  [
    let data file-read-line
    if not (first data = "#")   ;; prevent reading of the first line
    [
      set data split data " "   ;; split location indicated by a space
      let node1 table:get nodes item 0 data
      let node2 table:get nodes item 1 data
      ask node1 [create-newroad-with node2 
        [
          set roadtype last data 
        ]]
      ask newroads
        [
          if roadtype = "highway" [set color 33 set thickness 0.5]
          if roadtype = "major_road" [set color 34 set thickness 0.5]
          if roadtype = "loose_road" [set color 35 set thickness 0.5]
          if roadtype = "small_road" [set color 36 set thickness 0.5]
          if roadtype = "field_road" [set color 37 set thickness 0.25]
        ]
    ]
  ]
  file-close
  print "roads: "
  print newroads
  print [roadtype] of newroads
  ;;ai:20120118
  ask newroads [set road-patches patches with [patch-near-link? self myself]] ;;ai: every road keeps a set of neaby patches
  ask newroads with [roadtype = "major_road"] [ask road-patches [set pcolor red]]
  ask newroads with [roadtype = "loose_road"] [ask road-patches [set pcolor violet]]
  ask newroads with [roadtype = "small_road"] [ask road-patches [set pcolor pink]]
end

to setup-patches
  ask patches                     ;; initialization: all patches are growing rice fields
  [
    set patch-type "ricefield"    ;;this inital value will change when we change the patch type
    set field-state "growing"
    set field-patches nobody
    set occupant nobody
    set road-access min-one-of ( intersections )[ distance myself ]  ;;ai: note that min-n-of produces an agentset!
    set pcontaminated? FALSE
  ]
  
  setup-edge-patches

  ;;;; PLACE OBJECTS ALONG ROADS
  let my-major-roads newroads with [roadtype = "major_road"]
  let my-loose-roads newroads with [roadtype = "loose_road"]
  let my-small-roads newroads with [roadtype = "small_road"]
  ;; place match arenas
  place-along-roads N-MATCH-ARENAS "match-arena" my-loose-roads
  set match-arenas patches with [ patch-type = "match-arena" ]
  ask match-arenas [set infected-outsider-FC-here? FALSE ]                   ;;**************20120410 AB Altered the transmission procs of FC a bit below
  ;; place practice arenas                                                          ;; we need to determine how to make this a chance of infection at the arena
  place-along-roads-north (N-PRACTICE-ARENAS / 3) "practice-arena" my-loose-roads   ;; becuase when this is TRUE, the arena infects a FC every time.
  place-along-roads-south (N-PRACTICE-ARENAS / 3) "practice-arena" my-loose-roads
  place-along-roads (N-PRACTICE-ARENAS / 3) "practice-arena" my-loose-roads
  set practice-arenas patches with [ patch-type = "practice-arena" ]
  ask practice-arenas [set infected-outsider-FC-here? FALSE set practice-arena-number ""] ;;*********************
  ask one-of practice-arenas [set practice-arena-number 1]
  ask one-of practice-arenas with [practice-arena-number = ""] [set practice-arena-number 2]
  ask one-of practice-arenas with [practice-arena-number = ""] [set practice-arena-number 3]
  ;; place markets
  place-along-roads N-MARKETS "market" my-major-roads
  set markets patches with [ patch-type = "market" ]
  ;; place cooperatives
  place-along-roads-north N-COOPERATIVES "cooperative" my-major-roads
  set cooperatives patches with [ patch-type = "cooperative" ]
  ;; place barns (60%, 30% and 10% around major, loose and small roads)
  place-along-roads round (0.6 * N-BARNS) "barn" my-major-roads
  place-along-roads round (0.3 * N-BARNS) "barn" my-loose-roads
  place-along-roads round (0.1 * N-BARNS) "barn" my-small-roads
  set barns patches with [ patch-type = "barn" ]
  
  ;; place out-of-subdistrict-patches
  set out-of-subdistrict-patches (patch-set patch -29 15 patch 29 15)
  ask out-of-subdistrict-patches [set patch-type "out" set field-state ""]

  setup-ricefields 
  ask patches [ set-patch-visuals ]
end ;; setup-patches


to setup-edge-patches
  ;; make all edge patches growing fields so that turtles don't hit wall
  ;; (draws on the Look Ahead Example Model in Library)
  set edge-patches patches with [count neighbors != 8]
  ask edge-patches [
    set patch-type "edge"
    set field-state ""
  ]
end


to place-along-roads [#num #type #roads]
  let %patches ((patch-set [road-patches] of #roads) with [(not any? turtles-here) and (patch-type = "ricefield")])
  ask n-of #num %patches [ 
    set patch-type #type
    set field-state ""
  ]
end

to place-along-roads-north [#num #type #roads]
  let %patches ((patch-set [road-patches] of #roads) with [(not any? turtles-here) and (patch-type = "ricefield") and ( pycor > 0)])
  ask n-of #num %patches [ 
    set patch-type #type
    set field-state ""
  ]
end

to place-along-roads-south [#num #type #roads]
  let %patches ((patch-set [road-patches] of #roads) with [(not any? turtles-here) and (patch-type = "ricefield") and ( pycor < 0)])
  ask n-of #num %patches
  [ 
    set patch-type #type
    set field-state ""
  ]
end


to setup-ricefields ;;observer proc
  set rice-fields (patches with [ field-state = "growing" ])  ;;intialize global variable

  ;create-fields num-fields-harvested   ;; augments the ``access-fields`` global
  new-create-fields
  ask access-fields [
    harvest-field                               ;;changes field-state (and color), makes rai available
  ]

  show (word "total rai available at sim start is " sum [rai] of access-fields)
  show (word "this shd match " sum [rai] of patches)
    
  ;; make number of harvested fields determined by slider to be contaminated
  if influenza? [ 
    ask n-of num-fields-contam access-fields [                                                             
      contaminate-field                     ;;ai20110815 (just matches what you have been doing, but perhaps shd change) chk
    ]
  ]
end

to new-create-fields  ;; observer proc
  if (debug > 5) [show "enter proc: create-fields"]
  let %avradius 9
  ;; create the field-access patches
  let %y min-pycor + (%avradius / 2)
  while [%y < max-pycor] [
    let %x min-pxcor + (%avradius / 2)
    while [%x < max-pxcor] [
      let %new-access-field patch %x %y 
      if ([field-state] of %new-access-field = "growing") [
        set access-fields (patch-set access-fields %new-access-field)
      ]
      set %x (%x + %avradius)
    ]
    set %y (%y + %avradius)
  ]
  show (word (count access-fields) " access fields created")
  let %n-access-fields 0
  ;; number the access fields and set their size
  ask access-fields [
    set %n-access-fields (%n-access-fields + 1)
    set field-num %n-access-fields
    set rai random-pert 80 150 610 
  ]
  ;; make minimal fields around the access patch
  ask access-fields [
    let %field patch-set [neighbors] of neighbors
    ask %field with [field-state = "growing" and field-num = 0] [ ;; does *not* include the access-field patch
      set field-num [field-num] of myself
    ]
  ]
  ;; fill in the fields
  ask access-fields [
    let %n-patches (rai / 2)
    let %radius ceiling sqrt (%n-patches / 3)
    let %field patches in-radius %radius with [field-state = "growing" and field-num = 0]  ;; does *not* include the access-field patch
    ask %field [
      set field-num [field-num] of myself
    ]
  ]
  ;; attach remaining rice-field patches to fields
  ask patches with [field-state = "growing" and field-num = 0] [
    let %field-patches patches with [field-state = "growing" and field-num != 0]
    set field-num [field-num] of min-one-of %field-patches [distance myself]
  ]
  ask access-fields [
   set field-patches (patches with [field-num = [field-num] of myself])    ;; *include* the access patch
  ]
  if (debug > 5) [show "exit proc: create-fields"]
end


; to create-fields [#num]  ;; observer proc
;   if (debug > 5) [show "enter proc: create-fields"]
;   ;; randomly create growing fields
;   let %new-access-fields n-of #num rice-fields with [field-state = "growing" and field-num = 0]
;   set access-fields (patch-set access-fields %new-access-fields)
;   ;; number the field-access patches
;   ask %new-access-fields [ 
;     set n-access-fields (n-access-fields + 1)
;     set field-num n-access-fields               ;; unique field identifier
;   ]
;   ;; create the fields
;   ask %new-access-fields [
;     let %field patch-set [neighbors] of neighbors
;     set %field %field with [field-state = "growing" and field-num = 0]  ;; does *not* include the access-field patch
;     ask %field [
;       set field-num [field-num] of myself
;     ]
;     set field-patches (patch-set self %field)    ;; *include* the access patch
;   ]
;   if (debug > 5) [show "exit proc: create-fields"]
; end

to harvest-field ;;patch (access field) proc
  if (debug > 3) [show "enter proc: harvest-field"]
  if (field-state != "growing") [ __error (word "field-state '" field-state "' shold be 'growing'")]
  if (field-patches = nobody) [ __error "apply harvest-field proc only to access fields"]
  set rai random-pert  80 150 610 
  show (word "provides access to " rai " rai")
  ask field-patches [ set field-state "harvested" set pcolor COLOR-HARVESTED]
  if (debug > 3) [show "exit proc: harvest-field"]
end

to fallow-field ;;patch (access field) proc
  if (debug > 3) [show "enter proc: fallow-field"]
  if (field-state != "harvested") [
    let %msg (word "patch " self " has field-num " field-num " and field-patches " field-patches)
    show %msg
    __error (word %msg "field-state '" field-state "' shold be 'harvested'")
  ]
  if (field-patches = nobody) [ __error "apply fallow-field proc only to access fields"]
  set rai 0                ;; "wasted rai" chk!
  ask field-patches [ set field-state "fallow" set pcolor COLOR-FALLOW]
  if (debug > 3) [show "exit proc: fallow-field"]
end

to set-patch-visuals
  ;; initialize color globals (for patches that may change color)
  set COLOR-FALLOW 48
  set COLOR-HARVESTED yellow
  set COLOR-GROWING 57 ;; light green
  ifelse (field-state != "")
  [
    if (field-state = "fallow") [ set pcolor COLOR-FALLOW ]
    if (field-state = "harvested") [ set pcolor  COLOR-HARVESTED]
    if (field-state = "growing") [ set pcolor COLOR-GROWING ]
  ]
  [
    if (member? self match-arenas) [ set pcolor red set plabel "A"]
    if (member? self practice-arenas) [ set pcolor red set plabel "P" ]
    if (member? self barns) [ set pcolor (blue + 1) ]
    if (member? self markets) [ set pcolor violet set plabel "M"]
    if (member? self cooperatives) [ set pcolor violet set plabel "C"]
    if (member? self edge-patches) [ set pcolor white ]
    if (member? self out-of-subdistrict-patches) [set pcolor brown set plabel "OUT"]
  ]
end



;;;;;;;;;;;;
;; Agents ;;
;;;;;;;;;;;;

to setup-agents
  if (debug > 3) [show "enter proc: setup-agents"]
  
  setup-livetraders
  setup-fgds 
    
  ;;BYOWNERS: sprout backyard poultry owners from barn patches, assign a certain number to have fighting cocks
  ask n-of N-BYOWNERS barns with [ not any? turtles-here ] [
    sprout-byowners 1 [ set home-patch patch-here init-byowner ]        
    sprout-bychickens 1 [ init-bychickens ] 
  ]
  ask n-of N-PRACTICE-ARENAS practice-arenas with [ not any? turtles-here ] [
    sprout-byowners 1 [ set home-patch patch-here init-byowner ]        
    sprout-bychickens 1 [ init-bychickens ] 
  ]
  ask n-of num-bychick-inf bychickens [infect-initial]         ;; set some of the backyard chicken flocks as infectious
  
  ;ai20120110: fcowners membership won't change
  set fcowners (turtle-set (byowners with [patch-type = "practice-arena"])
  (n-of (N-FCOWNERS - N-PRACTICE-ARENAS) (byowners with [patch-type = "barn"])))
  ask fcowners [ set own-fightingcocks? true ]
  
  ;;BYDUCKOWNERS: sprout backyard duck owners from barn patches          
  ask n-of N-BYDUCKOWNERS barns with [ not any? turtles-here ] [
    sprout-byduckowners 1 [ set home-patch patch-here init-byduckowner ]
    sprout-byducks 1 [ init-byducks ] 
  ]
  ask n-of num-byduck-inf byducks [infect-initial]         ;; set some of the small duck flocks as infectious
  
  ;;FARMOWNERS: sprout farm owners from barn patches                       
  ask n-of N-FARMOWNERS barns with [ not any? turtles-here ] [
    sprout-farmowners 1 [ set home-patch patch-here init-farmowner ]
    sprout-farms 1 [ init-farms ] 
  ]
  ask n-of num-farm-inf farms [infect-initial]         ;; set some of the egg farms as infectious
  

  ;;;; Establish visit-lists for all poultry owners
  ;;ai20120110: (but left it as you had it: no visit-list for eggtraders and livetraders)
  ;;  comment: this does not ensure the neighbor will be home when visited! 
  ;;  ab response: This is ok, we are more concerned about the feces on the ground that the visitor might step in
 ; let humans turtles with [member? breed human-types]
  set poultry-owners (turtle-set byowners fgd-owners byduckowners farmowners)  ;chk must be complete list
  ask poultry-owners [
    let my-home-patch home-patch
    ;; visit-list is a patch-set
    ;; (note: all neighbors within a radius of 10 are equally likely to be in the visit-list) chk hard-coded visit-radius
    set visit-list min-n-of random-visit-int
      (patch-set [home-patch] of other turtles with [ member? breed human-types])
      [int (distance my-home-patch / 10)]
    if (debug >= 5) [ show (word "turtle " who " with type " breed " has visit list: " [self] of visit-list) ]
    if (debug >= 5) [ ask visit-list [show (word "\tdistance: " (distance myself))] ]
  ]
  
  set-egg-types
  set-egg-transfer-days
  make-egg-pickup-network
  set-eggtrader-type
  setup-fighting-cocks
;  print "set up fighting cocks"
  
  if (debug > 3) [show "exit proc: setup-agents"]
end

to setup-livetraders
  ;; distribute livetraders roughly evenly spaced on a circule around the center of the subdistrict
  ;; (livetraders trade live birds)
  let %cx ((min-pxcor + max-pxcor) / 2)
  let %cy ((min-pycor + max-pycor) / 2)
  let %center patch %cx %cy
  let %radius int min (list (max-pxcor - min-pxcor) (max-pycor - min-pycor)) / 3
  let %locations (list )
  let %rotation (360 / N-LIVETRADERS)
  let %offset (%rotation / 2)
  foreach n-values N-LIVETRADERS [?] [
    ask %center [set %locations lput patch-at-heading-and-distance (%offset + ? * %rotation) %radius %locations]
  ]
  foreach %locations [
    let %location ?
    let %okbarns barns with [not any? turtles-here]
    ask min-one-of %okbarns [distance %location] [
      sprout-livetraders 1 [ set home-patch patch-here init-livetrader ]
    ]
  ]
end

to setup-fgds
  ;;FGD: sprout num-fgd FGD flocks from barn (home patch) patches
  let %owner nobody
  let %fgd nobody
  let %n-barn-fgds (ceiling ((prop-fgd-barntofield) * N-FGD ))
  let %n-field-fgds (N-FGD - %n-barn-fgds)
  ;; some fgds will have barns to go to
  ask n-of %n-barn-fgds barns with [ not any? turtles-here ] [
    sprout-fgd-owners 1 [
      init-fgdowner
      set field-only? FALSE
      set %owner self
    ]
    sprout-fgds 1 [
      init-fgd
      set field-only? FALSE
      set %fgd self set owner %owner
    ]
  ]
  ;; some fgds will stay on their fields
  ask n-of %n-field-fgds access-fields with [not any? turtles-here] [
    sprout-fgd-owners 1 [
      init-fgdowner
      set field-only? TRUE
      set %owner self
    ]
    sprout-fgds 1 [
      init-fgd
      set field-only? TRUE
      set %fgd self set owner %owner
    ]
    ask %owner [create-fgd-link-with %fgd [tie hide-link show (word self " tied")]]
  ]
  ;; set some of the fgd flocks as infectious
  ;; ai chk: I'd like to move this to a "setup-infection" proc
  ask n-of num-fgd-inf fgds [infect-initial]

  ;;old version of tie creation
  ;ask fgds with [field-only?] [
  ;   create-fgd-link-with one-of turtles-here with [breed = fgd-owners] [tie]
  ;   print (word who " is tied")
  ; ] 
  ;ask fgd-links [ hide-link ]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Agent Initializations ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

to init-fgdowner
  set home-patch patch-here
  set can-contaminate? FALSE
  set egg-type "duck"
  set egg-pickup? FALSE
  set egg-delivery? FALSE
  set eggs-gone? FALSE
  set contaminated? FALSE
  set infectious? FALSE                 ;; The number of traders per FGD flock will vary, as determined by a PD
  set onsite-trader-num random-weighted [ 1 2 3 4 ] [ 0.513 0.38 0.099 0.0078 ]   
;  print (word "flock " who " has " onsite-trader-num " onsite traders")                
  set livebirds-gone? FALSE
  set n-visit-days-per-week binomial 7 0.42857
  ;; attributes for visualization
  set size 1 
  set color white
end

to init-fgd  ;;initializations for an fgd
  set home-patch patch-here
;  let rw-values n-values 23 [(? + 1) * 1e-3]
;  let rw-weights [ 0.0037 0.0383 0.0728 0.0846 0.0844 0.0796 0.0814 0.0794 0.0715 0.0645 0.0605 0.0534 0.0479 0.0393 0.0303 0.027 0.0222 0.0178 0.015 0.01 0.0069 0.0051 0.0044 ]
  set n-ducks 2000   ;;Right now, the flock size is set at 2000 ducks. This may be changed in the future, and road contamination can also be made a continuous variable based
  set infectious? FALSE            ;; on flock size and shedding amount per duck. 
  set exposed? FALSE
  set latent? FALSE
  set recovered? FALSE
  set heading 270
  set color white
  set size 2
  set target-field nobody  ;;ai20110815
  set can-contaminate? TRUE
  set egg-type ""
  set eggs-gone? FALSE
  set egg-pickup? FALSE
  set egg-delivery? FALSE
end

to init-byowner
  set color (orange + 2)
  set size 1 
  set can-contaminate? FALSE
  set egg-type ""
  set egg-pickup? FALSE
  set egg-delivery? FALSE
  set eggs-gone? FALSE
  set own-fightingcocks? FALSE
  set livebirds-gone? FALSE
  set practice-fight-week? FALSE
  set match-fight-week? FALSE
  set onsite-trader-num 0
  set own-infected-flock? FALSE
  set contaminated? FALSE
  set latent? False
  set infectious? FALSE
  set recovered? FALSE
  set n-visit-days-per-week binomial 7 0.42857   ;; number of visiting day (add explanation chk )
end

to init-byduckowner
  set color (brown + 2)
  set can-contaminate? FALSE
  set egg-type ""
  set egg-pickup? FALSE                  ;; 28 will be meat only, 41 will be egg only, 11 will be egg and meat
  set egg-delivery? FALSE                ;; of those that will have eggs (52 flocks), half will pick up and half will deliver
  set eggs-gone? FALSE
  set onsite-trader-num 1                  ;; The number of traders per small duck flock will stay 1
  set livebirds-gone? FALSE
  set own-infected-flock? FALSE
  set contaminated? FALSE
  set byduck-type ""
  set n-visit-days-per-week binomial 7 0.42857
end

to init-farmowner
  set color (yellow + 2)
  set can-contaminate? FALSE
  set egg-type ""
  set egg-pickup? FALSE
  set egg-delivery? FALSE
  set eggs-gone? FALSE                   ;; The number of traders per farm will vary, as determined by a PD
  set onsite-trader-num random-weighted [ 1 2 3 4 5 6 7 8 ] [ 0.2216 0.3602 0.2156 0.1171 0.0548 0.0223 0.0071 0.0013 ]   
;  print (word "farm " who " has " onsite-trader-num " onsite traders")  
  set livebirds-gone? FALSE
  set own-infected-flock? FALSE
  set contaminated? FALSE
    set n-visit-days-per-week binomial 7 0.42857
end

to init-bychickens
  set color orange
  set infectious? FALSE 
  set exposed? FALSE
  set latent? FALSE
  set recovered? FALSE
  set death? FALSE
end

to init-byducks
  set color brown
  set infectious? false
  set exposed? FALSE
  set latent? False
  set recovered? FAlse
  set byduck-type ""
end

to init-farms
  set color yellow
  set infectious? FALSE
  set exposed? FALSE
  set latent? FALSE
  set recovered? FALSE
  set death? FALSE
end

to init-eggtrader
  set color (pink + 1)
  set size 1  
  set can-contaminate? FALSE         ;; traders cannot contaminate, becuase i do not want them to contaminate the roads
  set contaminated? FALSE            ;; traders may contaminate the target-farm, so this is a separate command
  set n-eggtrader-links RANDOM-PERT 1 1 10       ;; varied this for Se analysis- tested 1 and 10
 ; print (word "Egg trader " who " services " n-eggtrader-links " farms")               
  set egg-type ""
end

to init-livetrader
  set color (magenta + 1)
  set size 1  
  set label-color (blue - 2)
  set can-contaminate? FALSE
  set egg-type ""
  set contaminated? FALSE
  set egg-pickup? FALSE
  set egg-delivery? FALSE
  set n-bird-pickup-days random 3      ;; Each live trader will be assigned a random number (0, 1, 2), which will indicate the number of trading days (1, 2, 3)
;  print (word "livetrader " who " has " n-bird-pickup-days " bird-pickup-days.")
end



;;;;;;;;;;;;;;;;;
;; Egg Network ;;
;;;;;;;;;;;;;;;;;

to set-egg-types
  ;;ai: remove hardcoded numbers chk
  ifelse co-op?  [
    ask fgd-owners [set egg-delivery? true]
  ] [
    ask fgd-owners [set egg-pickup? true set egg-delivery? false]
    ask n-of (floor N-FGDOWNERS / 2) fgd-owners [set egg-delivery? true set egg-pickup? false ]
  ]

  ;;ai: remove hardcoded numbers chk
  ;; of those byduck flocks that will have eggs (52 flocks), half will pick up and half will deliver
  ask n-of 26 byduckowners [set egg-pickup? true set byduck-type "egg" set egg-type "duck"]
  ask n-of 26 byduckowners with [egg-pickup? = false] [set egg-delivery? true set byduck-type "egg"
    set egg-type "duck"]
  ask byduckowners with [byduck-type = "" ] [set byduck-type "meat"]
  ask byducks with [any? byduckowners-here with [byduck-type = "egg"]] [set byduck-type "egg"]
  ask byducks with [byduck-type = ""] [set byduck-type "meat"]                         ;; label flocks as egg of meat ducks

  ask farmowners [set egg-type "chicken"] ;;currently 9
  ask n-of 3 farmowners [set egg-type "duck"] ;;ai: remove hardcoded numbers chk
  ;; of the 6 large chicken egg farms, 2 have pickup, 2 delivery and 2 both
  ;; of the 3 large duck egg farms, 1 has pickup, 1 delivery and 1 both
  let my-ct 0
  foreach ["chicken" "duck"] [
    let my-egg-type ?
    ask farmowners with [egg-type = my-egg-type] [
      let my-type (my-ct mod 3) 
      if (my-type = 0) [set egg-pickup? true set egg-delivery? false]
      if (my-type = 1) [set egg-pickup? false set egg-delivery? true]
      if (my-type = 2) [set egg-pickup? true set egg-delivery? true]
      set my-ct (my-ct + 1)
    ]
    set my-ct 0
  ]

  ;;ai: why aren't farms patches? chk
  ask farms with [any? farmowners-here with [egg-type = "chicken"]] [ set egg-type "chicken"]
  ask farms with [any? farmowners-here with [egg-type = "duck"]] [ set egg-type "duck"]
  
end

to set-egg-transfer-days
  ;; The number of pickup days will vary for each egg supplier;
  ask farmowners with [egg-pickup?] [
    set pickup-days random-weighted [ 2 3 7 ] [ 0.33 0.33 0.33 ] ;;based on small amount of interview data.        
  ]
  ask fgd-owners with [egg-pickup?] [
    set pickup-days random-weighted [ 1 2 3 7 ] [ 0.073 0.635 0.197 0.095 ] ;; based on large survey data
  ]
  ask byduckowners with [egg-pickup?] [
    set pickup-days random-weighted [ 1 2 3 7 ] [ 0.073 0.635 0.197 0.095 ] ;; same distribution as FGD
  ]
    
  ;; The number of delivery days will vary for each supplier
  ask farmowners with [egg-delivery?] [
    set delivery-days random-weighted [ 2 3 7 ] [ 0.33 0.33 0.33 ]    
  ]
  ask fgd-owners with [egg-delivery? ] [
    set delivery-days random-weighted [ 1 2 3 7 ] [ 0.087 0.522 0.174 0.217 ] ;; based on large survey data
  ]
  ask byduckowners with [egg-delivery? ] [
    set delivery-days random-weighted [ 1 2 3 7 ] [ 0.087 0.522 0.174 0.217 ] ;; same distribution as FGD
  ]
end

;;Goals for ``make-egg-pickup-network``:
;;1. set the number of egg-traders "needed" by each turtle (i.e., onsite-trader-num)
;;2. set the number of sites each eggtrader can visit to 2 now, later randomly (i.e., n-eggtrader-links)
;;3. create just as many eggtraders as are needed
;;4. create eggtraders fairly close to their suppliers
;;5. associate each eggtrader with a barn, where a barn is associated with 0 or 1 eggtraders
to make-egg-pickup-network
  let %suppliers turtles with [ egg-pickup? = True ]
  ;start with every barn having a potential egg-trader
  ask barns 
  ;with [not any? turtles-here]                 ;; 20120327 ab: We did not set up enough barns to support eggtraders alone; they can share patches.
  [
    sprout-eggtraders 1 [ set home-patch patch-here init-eggtrader ]
  ] 
  
  ;; each egg trader makes links to suppliers (until suppliers all taken)
  ;; eggtraders with no suppliers are removed from the simulation
  ask eggtraders [
    carefully [
      create-egg-links-from min-n-of n-eggtrader-links %suppliers with [ count my-out-links < onsite-trader-num ]
      [distance myself]
    ] [
      die
    ]
  ]
  ask egg-links [ hide-link ]
  ask eggtraders [ set target-market one-of markets ]
end

to set-eggtrader-type
  ask eggtraders
  [
    ifelse all? in-link-neighbors [egg-type = "chicken"]
    [ set egg-type "chicken"] 
    [
      ifelse all? in-link-neighbors [egg-type = "duck" ]
      [set egg-type "duck"]
      [
        if any? (in-link-neighbors with [egg-type = "duck"]) and any? (in-link-neighbors with [egg-type = "chicken"])
        [set egg-type "duck and chicken"]
      ]
    ]
  ]
end
      
;;;;;;;;;;;;;;;;;;
;;Fighting Cocks;;
;;;;;;;;;;;;;;;;;;     
     
      
to setup-fighting-cocks
;  let practice-arena-1 practice-arenas with [practice-arena-number = 1]
;  let practice-arena-2 practice-arenas with [practice-arena-number = 2]
;  let practice-arena-3 practice-arenas with [practice-arena-number = 3]
;  ask min-n-of (floor N-fcowners / N-practice-arenas) fcowners [distance practice-arena-1]
;    [
;       set target-practice-arena practice-arena-1
;    ]
; ask min-n-of (floor N-fcowners / N-practice-arenas) fcowners [distance practice-arena-2]
;    [
;       set target-practice-arena practice-arena-2
;    ]
; ask fcowners with [target-practice-arena = nobody]
;    [
;       set target-practice-arena practice-arena-3
;    ]
 ask fcowners
  [
    set target-match-arena min-one-of match-arenas [ distance myself ] 
    ;print (word "FC " who " chose arena" ([pxcor] of target-match-arena) ([pycor] of target-match-arena))
    set target-practice-arena one-of practice-arenas
   ; print (word "FC " who " chose practice arena" ([pxcor] of target-practice-arena) ([pycor] of target-practice-arena))
  ]
  
  ;;ai: chk So I'm commenting out the next two lines and replacing them with what I think you intend
  ;;ask fcowners [ if [pycor] of target-practice-arena > 0 [ if random-float 100 < 50 [ set practice-fight-week? true ]]]  ;; about half of those at each practice arena bring cocks to fight
  ;;ask fcowners [ if [pycor] of target-practice-arena < 0 [ if random-float 100 < 50 [ set practice-fight-week? true ]]]
 ; ask n-of (N-FCOWNERS / 8) fcowners [set practice-fight-week? true set practice-fight-week 1]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Go procedures  ;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  file-open location-datafile
  file-print (word "day " (ticks + 1))
  file-close
  ifelse runsim? [
    update-calendar
    ;; having egg trading first facilitates the transmission process, since
    ;; contam of the egg trader depends on there being infectious turtles, not infected patch.   
    ask eggtraders [ pickup-eggs ]

    ask fgds [go-to-field]  ;field-only fgds may need a new field

    ask fgd-owners [ fgd-deliver-eggs ]
    ask farmowners [deliver-eggs ]
    ask byduckowners [deliver-eggs ]

    ;; chk need *all* livebird suppliers
    ask (turtle-set byduckowners byowners) with [livebirds-gone?] [ set-livebird-availability ]
    ask livetraders [livetrader-pickup]
    ask links with [ color = blue ] [ die ]          ;; clear the links after the trading day, because new network on the next day

    
    fight-cocks

    ask fgds with [not field-only?] [
      travel-roads-to home-patch 
    ]

    ask fgd-links [untie print (word end1 "untied for visiting")]
    ask (turtle-set byowners fgd-owners byduckowners farmowners) [visit]
    ask fgd-links [tie print (word end1 "tied after visiting")]

    if influenza? [
      ask bychickens [ road-infect-backyard ]
      
      ask byducks [road-infect-penned]
      ask farms [road-infect-penned]
      
      ask barns [set-road-contam-time] 
      ask practice-arenas [set-road-contam-time]
      ask turtles with [member? breed poultry-types] [add-influenza-day change-state ]
      ask turtles with [member? breed trader-types] [ set-trader-contam-time]
      ask byowners [add-influenza-day change-state]
    ]

    
    do-plots                                                ;; do-plots has to be placed before decontamination of traders, locations
    ask turtles with [member? breed trader-types] [decontaminate-traders]
    ask patches [decontaminate-roads decontaminate-fields]
    tick
    
    test-for-endsim
  ][
    print (word "Simulation stopped: " stop-sim-reason)
    stop
  ]
  test-go
end

to update-calendar
  type (word "ticks is " ticks ". ")
  set day-idx (ticks mod 7)
  set day-name item day-idx DAY-NAMES
  set week int (ticks / 7)
  set livetrader-pickup-days item day-idx LIVETRADER-PICKUP-SCHEDULE
  set eggtrader-pickup-days item day-idx DAY-SCHEDULE
  set visit-days item day-idx DAY-SCHEDULE
  print (word day-name " of week " week " is starting!!")
  foreach table:keys transmissions [
    table:put transmissions ? (lput 0 table:get transmissions ?)
  ]
  foreach table:keys contaminations [
    table:put contaminations ? (lput 0 table:get contaminations ?)
  ]
end


;;;;;;;;;;;;;;;;;
;;Grazing Procs;;
;;;;;;;;;;;;;;;;;

to go-to-field  ;; fgd proc
  if (debug > 5) [show "enter proc: go-to-field"]
  set-target-field                ;;also sets occupant on target fields and homepatch of field-only fgd-owners!
  travel-roads-to target-field
  graze-here ;; chk make infection possible during grazing?
  if (debug > 5) [show "exit proc: go-to-field"]
end

to set-target-field ;; fgd proc
  ;;change target if needed (otherwise do nothing)
  if (debug > 5) [show "enter proc: set-target-field"]
  if ((target-field != nobody) and (member? target-field out-of-subdistrict-patches)) [stop] ;; chk out of sim forever ...
  let %rai-needed (n-ducks * RAI-PER-DUCK)
  if (debug > 3) [show (word "rai-needed: " %rai-needed)]
  let %old-target target-field
  if ((%old-target != nobody) and ([rai] of %old-target < %rai-needed)) [
    if (debug > 3) [ show (word "rai available (" ([rai] of %old-target) ") is inadequate; change target.") ]
    ask %old-target [
      set occupant nobody
      fallow-field
    ]
    set %old-target nobody
  ]
  ifelse (%old-target = nobody) [ ; set a new target
    let %candidates access-fields with [(rai >= %rai-needed) and (occupant = nobody)]
    if (not any? %candidates) [
      show "WARNING: no unoccupied fields left with adequate rai; move flocks out of district"
      set %candidates out-of-subdistrict-patches
      show " moving out of district"
    ]
    let %new-target min-one-of %candidates [ distance myself ]
    set target-field %new-target
    ask target-field [set occupant self]
    show (word " chose target field " target-field ". ")
    if (field-only?) [
      set home-patch %new-target
      ask owner [set home-patch %new-target move-to home-patch]
    ]
    ;; update days on field
    let %who ([who] of self)
    table:put days-on-field %who (lput 0 table:get days-on-field %who)
  ][
    let %who ([who] of self)
    let %oldlist table:get days-on-field %who
    table:put days-on-field %who (lput (last %oldlist + 1) butlast %oldlist)
  ]
  if (debug > 5) [show "exit proc: set-target-field"]
end

to graze-here  ;; fgd proc
  if ((debug > 3) and (member? patch-here out-of-subdistrict-patches)) [
    show "grazing out of subdistrict"
  ]
  let consume (n-ducks * RAI-PER-DUCK)
  set rai (rai - consume)  ;; rai is a patch attribute                   CONTAM FIELD HERE?
  if (infectious? = TRUE) [risk-ground-contamination "flock-field"]
 ; expose
end    

;;;;;;;;;;;;;;;;;;
;;Movement Procs;;
;;;;;;;;;;;;;;;;;;

to travel-roads-to [#target]  ;; turtle proc, #target is a patch
  if (debug > 5) [show (word "enter proc: travel-roads-to with target " #target)]
  if (debug > 3) [show (word "traveling to " #target)]
  if ((debug > 3) and (member? #target out-of-subdistrict-patches)) [
    show "traveling out of subdistrict"
  ]
  if (#target = nobody) [ show "not give a target!" __error "no target" ]
  if (#target = patch-here) [show "already at target" stop]
  let intA road-access
  let intB [road-access] of #target
  let path-nodes 0  ;;ai: just an initialization
  let path-links 0
  ask intA [
    set path-nodes __network-shortest-path-nodes intB newroads
    set path-links __network-shortest-path-links intB newroads
  ] 
  print (word "short path from " intA " to " intB " is " path-nodes)
  print (word "short path from " intA " to " intB " is " path-links)
  ;;ai: need to confirm that all nodes are connected via roads ...
  ifelse (length path-nodes = 0) [ 
    show (word "WARNING: no roads from " intA " to " intB)
    move-to intB
    set path-nodes (list intA)
  ][
    if (debug > 3) [show "traveling roads"]
  ]
  move-to intA    ;;ai this moves to the road access of the current patch
  foreach but-first path-nodes [
    let next-node ?
    print (word "traveling to " next-node)
    face next-node
    while [distance next-node > 0.5] [forward 0.5]
    move-to next-node
  ]
  move-to #target
  if (debug > 3) [show (word "reached target" #target)]
  if infectious? [
    let %risks patch-set [road-patches] of link-set path-links
    ask %risks [ risk-ground-contamination "flock-road" ]
  ]
  if (debug > 5) [show (word "exit proc: travel-roads-to; current location " patch-here)]
end    


;;;;;;;;;;;;;;;;;;;;;
;; Egg Network Go! ;;
;;;;;;;;;;;;;;;;;;;;;


to pickup-eggs     ;; eggtrader proc
  ;; each day all egg traders assess if it is a pickup day for any of their contact flocks
  ;; if it is, they collect from flocks who have that pickup day.
  let %suppliers in-link-neighbors with [(not eggs-gone?) and member? pickup-days eggtrader-pickup-days] 
  if (not any? %suppliers) [show (word "no pickups on " day-name)]
  foreach [self] of %suppliers [
    move-to ?
    show (word "getting eggs from " ?)
    contaminate-eggtrader
  ]
  ;;after done collecting, take eggs to usual market
  move-to target-market                              ;;currently, we do not consider market infection from eggtraders
  move-to home-patch
end


to contaminate-eggtrader  ;; eggtrader proc
  if (not influenza?) [stop] ;; exit procedure
  if not (member? self eggtraders) [__error (word self " is not an eggtrader")]
  let %risks turtles-here with [member? breed poultry-types]
  ;; eggtrader may contaminate poultry here
  if (contaminated?) [
      ask %risks with [not (latent? or infectious? or recovered?)] [risk-transmission "eggtrader-flock"]
  ]
  ;; contaminate egg trader at inf farm
  if (any? %risks with [infectious?]) [
    risk-human-contamination "flock-eggtrader"
  ]
end

to risk-transmission [#type]  ;; poulty proc
  if (not influenza?) [stop] ;; exit proc
  if (latent? or infectious? or recovered?) [stop] ;;exit proc  chk
  let %p 0
  if (#type = "eggtrader-flock") [
    set %p eggtrader-flock-infect-prob
  ]
  if (#type = "livetrader-flock") [
    set %p livetrader-flock-infect-prob
  ]
  if (#type = "visitor-flock") [
    show  (word "to-visit-infect-prob:" to-visit-infect-prob)
    set %p to-visit-infect-prob
  ]
  if (#type = "after-visit") [
    set %p from-visit-infect-prob
  ]
  if (#type = "road-flock") [
    if breed = bychickens [
    set %p road-infect-byc-prob
  ]
   if ((breed = byducks) or (breed = farms)) [
    set %p road-infect-pen-prob
  ] 
  ]
  if (#type = "arena-fc") [
    set %p arena-FC-infect-prob
  ]
  if (#type = "fc-flock") [
    set %p FC-bkyd-infect-prob
  ]
  if (random-float 100 < %p) [
    infect-poultry
    let %oldct table:get transmissions #type
    let %newct lput (last %oldct + 1) butlast %oldct
    table:put transmissions #type %newct
  ]
end


to risk-human-contamination [#type]  ;; human proc
  if (not influenza?) [stop] ;; exit proc
  if (contaminated?) [stop]  ;; exit proc
  let %p 0
  if (#type = "flock-eggtrader") [
    set %p flock-eggtrader-contam-prob
  ]
  if (#type = "flock-livetrader") [
    set %p live-trader-contam-prob
  ]
  if (#type = "flock-visitor") [
    set %p 100
  ]
  if (random-float 100 < %p) [
    set contaminated? true
    show "is contaminated"
    let %oldct table:get contaminations #type
    let %newct lput (last %oldct + 1) butlast %oldct
    table:put contaminations #type %newct
  ]
end

to risk-ground-contamination [#type]  ;; patch proc
  if (not influenza?) [stop] ;; exit proc
  if (pcontaminated?) [stop]  ;; exit proc
  let %p 0
  if (#type = "flock-road") [
    set %p 100
  ]
  if (#type = "flock-field") [
    set %p 100
  ]
  if (random-float 100 < %p) [
    set pcontaminated? true
    show "is contaminated"
    let %oldct table:get contaminations #type
    let %newct lput (last %oldct + 1) butlast %oldct
    table:put contaminations #type %newct
  ]
end
    
to infect-poultry
  ;;if (latent? or infectious? or recovered?) [__error "wrong initial state for new infection"]
  ifelse (latent? or infectious? or recovered?) [show "WARNING: wrong initial state for new infection"]
  [ ;;chk
  set latent? TRUE
  set infection-time 0
  show (word "is infected")
  if breed = fcowners [set own-infected-fc? TRUE]
  record-infection
  ]
end

to record-infection
  file-open location-datafile
  file-show patch-here
  file-close
end

to deliver-eggs  ;;flock owner proc
  ;; deliver eggs to market
  if egg-delivery?
  [
    set target-market min-one-of markets [ distance myself ]    ;;chk move to set up?
    move-to target-market
    move-to home-patch
  ] 
end  

to fgd-deliver-eggs  ;; fgd-owner proc
  if (debug > 5) [show "enter proc: fgd-deliver-eggs"]
  if egg-delivery? [
    ask my-fgd-links [untie show (word "fgd-links untied for egg delivery")]
    ifelse co-op?
    [
      set target-market one-of cooperatives   ;chk move to setup?
;      print (word who " FGD chose co-op")
    ]
    [
      set target-market min-one-of markets [ distance myself ]    ;;chk move to set up?
;      print (word who " FGD chose market")
    ]
    move-to target-market
;    print (word who " FGD at target-market")
    move-to home-patch
    ask my-fgd-links [tie show (word "fgd-links retied after egg delivery")]
  ] 
  if (debug > 5) [show "exit proc: fgd-deliver-eggs"]
end


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Live Poultry Trading Network Go! ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Each day of the week, the livetraders are either delivering or not, based on the number of days per week they trade (1, 2 or 3)
;; There is no poultry trading network made at setup, because, unlike the egg trading network, it will change daily based on who they have already collectd birds from
;; On the Go command, each trader that trades on the present day will form a network of the 5 nearest houses that have not yet sold birds during the 2-month iteration

to set-livebird-availability ;; livebird supplier proc
  if (livebirds-gone? and ticks - livebird-selldate > 60) [   ;; chk hard coded number
    set livebirds-gone? FALSE    ;; livebirds available again after 2 months
    if (debug > 3) [show "livebirds-gone reset"]
  ]
end

to livetrader-pickup ;;livetrader proc (NEW VERSION)
  ;; each day each livetrader assesses if it is a pickup day for any of their contacts
  ;; if it is, collect live birds from flocks
  ;; comment: in this subdistrict, livetraders slaughter birds at home (live birds don't go to mkt)
  if (member? n-bird-pickup-days livetrader-pickup-days)[
    make-livetrader-pickup-network
    pickup-livebirds
  ]
end

to make-livetrader-pickup-network ;; livetrader proc
  ;; This is called by each trader, so it may be called 1, 2 or 3 times each week, depending on the trader's pickup schedule
  if (debug > 5) [show "enter proc: make-livetrader-pickup-network"]
  let %livebird-suppliers (turtle-set byduckowners byowners)  ;; chk shd include *all* suppliers
  set %livebird-suppliers (%livebird-suppliers with [not livebirds-gone?])
  let %ct min (list 4 count %livebird-suppliers) ;; chk hard coded number
  if (%ct < 4) [show (word "WARNING: not enough live birds available, run number " behaviorspace-run-number)]
  create-livebird-links-to min-n-of %ct %livebird-suppliers [distance myself]
  ask livebird-links [ set color blue ]
  if (debug > 5) [show "exit proc: make-livetrader-pickup-network"]
end

to pickup-livebirds   ;; livetrader proc
  let %collectingbirds? TRUE
  while [ %collectingbirds? ] [                                
    ifelse all? out-link-neighbors [livebirds-gone?] [ 
      set %collectingbirds? FALSE       ;; when they are done collecting for the day,
      move-to home-patch                ;; they go home, where they will slaughter the birds
    ] [ 
      let %livebird-supplier min-one-of out-link-neighbors with [not livebirds-gone?] [ distance myself ] 
      ;print (word "Live bird trader " who " chose pickup" ([pxcor] of %livebird-supplier) ([pycor] of %livebird-supplier))
      move-to %livebird-supplier
      ask %livebird-supplier [
        set livebirds-gone? TRUE
        set livebird-selldate ticks
      ]
      let %risks turtles-here with [member? breed poultry-types]
      ;; live trader may infect susceptible farm
      if (contaminated?) [
        ask %risks [risk-transmission "livetrader-flock"]
      ]
      ;; infected farm may contaminate live trader
      if (any? %risks with [infectious?]) [
        risk-human-contamination "flock-livetrader"
      ]
    ]
  ]
end





;;;;;;;;;;;;;;;;;;;;;;;
;;Fighting Cock Procs;;
;;;;;;;;;;;;;;;;;;;;;;;

to fight-cocks ;;observer proc (called in ``go``)
  if (debug > 3) [show "enter proc: fight-cocks"]
  if ((day-name != "Wednesday") and (day-name != "Sunday")) [
    type (word "No fighting cock activity today. ")
  ]
  if (day-name = "Wednesday") [ 
;    print (word day-name " practice matches")
    ;ask fcowners [move-to target-practice-arena]  ;;chk so *all* go to the practices. Right?
    ;let my-owners fcowners with [practice-fight-week = (int (ticks / 7)) mod 2] ;;half fight on even weeks, half on odd
    ask practice-arenas [ask n-of 20 (fcowners with [target-practice-arena = myself]) [move-to myself]]
    ask practice-arenas [show (word "There are " count fcowners with [target-practice-arena = patch-here ] " fc owners at this practice arena.")]  
    ask fcowners with [target-practice-arena = patch-here ] [ fight-here set practice-fight-week? TRUE] 
    ask fcowners with [practice-fight-week? != TRUE] [ set practice-fight-week? FALSE] 
;    type "FCs practicing are " print ([who] of fcowners with [practice-fight-week?])
;    type "Number of FCs fighting: " print (count fcowners with [practice-fight-week? = TRUE]) 
    ask fcowners [ move-to home-patch infect-backyard set practice-fight-week? FALSE]
  ];endif
  if (day-name = "Sunday") [ 
    ;; Only those who compete go to the matches. (Simplification.)
    ;; Each fc-owner brings a FC to the match arena about twice yearly;
    ;; thus we average N-FCOWNERS/26 cocks fighting per week.
    ;; (Was about 50/26~=2; raised it to 200/26~=8.)
    ;; That does not count cocks from other subdistricts.
    ;; Realistically, there are about 10 fights (20 cocks) on a day.
    ;; Do we have enough coming from our subdistrict?
    ;;ai: chk NOTE switching to fixed *number* of fc owners at matches!!  OK??
    ;; NOTE this still makes it so that only 2 owners from this subdistrict fight each week!
    ;; chk Add risk from by birds from other subdistricts???
    let my-owners n-of round (N-FCOWNERS / 26) fcowners
    ask my-owners [ 
      move-to target-match-arena
      fight-here 
;      print (word "FC owner " who " is fighting")
    ]
;    print (word day-name " fighting-cock matches:")
;    print (word "Number of FC owners at match: " count my-owners)
    ask my-owners [ 
      move-to home-patch
      infect-backyard
    ]
  ];endif
  if (debug > 3) [show "exit proc: fight-cocks"]
end

;to fight-here
;  if influenza?
;    [
;    if ((any? turtles-here with [(breed = fcowners) and (infectious? = true)]) or (infected-outsider-FC-here? = TRUE))   ;; 20120214 New.
;    [
;      if random-float 100 < arena-FC-infect-prob                              ;; if there are infectious flighting cocks at the arena, 
;      [                                                                 ;; infect the fighting cock in question with a prob of established at setup
;        set latent? TRUE                                                ;; fcowners are the only human-types that have a state transition.  
;        set color 117                                                   ;; starts as latent, color yellow and day 0 is set
;        set infection-time 0
;        set own-infected-fc? TRUE
;      ]
;    ]
;  ]
;end

to fight-here
  if influenza? [
    ;; 20120214 New.
    if ((any? turtles-here with [(breed = fcowners) and (infectious? = true)]) or (infected-outsider-FC-here? = TRUE)) [
      risk-transmission "arena-fc"
    ]
  ]
end

;;;;;;;;;;;;;;;;;;
;;Backyard Procs;;
;;;;;;;;;;;;;;;;;;

to visit ;;  poultry owner procedure
  ;; all poultry owners can move to a few neighbors daily for a visit
  ;; (number of visits per day determined by a binomial at initialization)
  if not member? self poultry-owners [__error "should be a poultry owner"]
  if member? n-visit-days-per-week visit-days  [
    if (any? turtles-here with [member? breed poultry-types and infectious?])    ;; contaminate owner at their house/barn
    [ set contaminated? TRUE]
    foreach ([self] of visit-list) [
;      show (word " at " patch-here " visiting " ?)
      move-to ?
      if (contaminated? = TRUE)
      [let %risks turtles-here with [member? breed poultry-types]         ;; expose flock at neighbor's house
        ask %risks [ risk-transmission "visitor-flock" ]
      ]
      if ((contaminated? = FALSE) and (any? turtles-here with [member? breed poultry-types and infectious?])) [
        risk-human-contamination "flock-visitor"
      ]
    ]
    
    ;; after visit, backyard owner may infect own flock
    move-to home-patch
    let %risks turtles-here with [member? breed poultry-types]           ;; we are still only accounting for one-way visitor infection. should be both ways?
    if (contaminated?) [
      ask %risks [
        risk-transmission "after-visit"
      ]
    ]
    set contaminated? FALSE                          
  ]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Contamination and Infection;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to infect-initial               ;; infect a flock at model setup
  if influenza? [
    set infectious? TRUE
    set color pink 
    set shedding-time 0
    ;record-infection chk current record separately
  ]
end

;to road-infect-backyard ;;bychicken proc
;  if (pcontaminated? = true) [
;    ;; road-infect-byc-prob is PERT based, as defined in setup chk
;    if (random-float 100 < road-infect-byc-prob) [ infect-poultry ]
;  ]
;end

to road-infect-backyard ;;bychicken proc                     ;; NEw AB 20120405
  if (pcontaminated? = true) [
    risk-transmission "road-flock"
  ]
end

;to road-infect-penned ;;byduck and farm proc                               ;; 20120327 AB: I have included a risk to penned ducks and farmed layer if raod contam
;  if (pcontaminated? = true) [
;    ;; road-infect-byc-prob is PERT based, as defined in setup chk
;    if (random-float 100 < road-infect-pen-prob) [ infect-poultry ]
;  ]
;end
                                                                           ;; New AB 20120405
to road-infect-penned ;;byduck and farm proc                               ;; 20120327 AB: I have included a risk to penned ducks and farmed layer if raod contam
  if (pcontaminated? = true) [
   risk-transmission "road-flock"
  ]
end

;to infect-backyard                       ;; in fighting procedures, ask fcowners to infect-backyard poultry
;  if influenza?                          ;; assumption is that is flock is not infected by the FC, then the infection dies and is not transported to neighbors
;  [
;    if ((own-infected-fc? = TRUE) and (not any? turtles-here with [member? breed poultry-types] with [(infectious? = true) or (latent? = TRUE) or (recovered? = TRUE)]))
;    [ if random-float 100 < FC-bkyd-infect-prob [ ask turtles-here with [member? breed poultry-types] [infect-poultry]]]    ;; 20120214 New.
;  ]
;end
                                          ;; New AB 20120405
to infect-backyard                       ;; in fighting procedures, ask fcowners to infect-backyard poultry
  if influenza?                          ;; assumption is that is flock is not infected by the FC, then the infection dies and is not transported to neighbors
  [
    if ((own-infected-fc? = TRUE) and (not any? turtles-here with [member? breed poultry-types] with [(infectious? = true) or (latent? = TRUE) or (recovered? = TRUE)]))
    [ ask turtles-here with [member? breed poultry-types] [risk-transmission "fc-flock"]] 
    set own-infected-fc? FALSE                                                    ;; 20120214 New.
  ]
end

to contaminate-field ;;ai20110815 patch proc             ;; This is where we will be able to give a continuous contamination value to the rice fields
  set field-contaminant (field-infection-prob / 100)     ;; This will be used if we want to generate an environmental SIR transition model for virus survival in fields
  set plabel "c"                                         ;; ai20110815 provisional (just matches what you have been doing, but perhaps shd change
  set plabel-color blue - 2                              ;; set label of contaminiated field
end


;;;;;;;;;;;;;;;;;;;;;;
;;Transmission Procs;;
;;;;;;;;;;;;;;;;;;;;;;

to change-state                                          ;; both ducks and chickens have a 1 day latent period. 
  if latent? [
    if infection-time > latent-period [ 
      set infectious? TRUE
      set latent? FALSE
      set color pink
      set shedding-time 1                                 ;; 20120410 Changed this to 1 becuase chx were shedding for one day too long
    ]                                                     ;; (go from 0 to 1 infection-time within the first day infected, but takes 
  ]                                                       ;; an extra tick to go from 0 to 1 for shedding time, so there was an extra day)
  if (breed = bychickens) or ((breed = farms) and (egg-type = "chicken"))[
    if infectious?  [
      ;; chickens have a 4 day shedding period. 
      if shedding-time > shedding-period-chicken [ 
        set recovered? TRUE
        set death? TRUE
        set infectious? FALSE
        set color gray
      ]
    ]
  ]
  if ((breed = byowners) and (own-fightingcocks? = TRUE ))[
    if infectious?  [
      ;; chickens have a 4 day shedding period. 
      if shedding-time > shedding-period-chicken [ 
        set recovered? TRUE
        set infectious? FALSE
        set color gray
        
      ]
    ]
  ]
  if ((breed = farms) and (egg-type = "duck")) or (breed = byducks) or (breed = fgds) [
    if infectious?  [
      ;; ducks have a 7 day shedding period. 
      if shedding-time > shedding-period-duck [ 
        set recovered? TRUE
        set infectious? FALSE
        set color gray
      ]
    ]
  ]
end

to add-influenza-day                                                        ;; how to keep time moving forward
  if latent? [
    set infection-time infection-time + 1 ]
  if infectious? [
    set shedding-time shedding-time + 1 ]
  set eggs-gone? FALSE
end

;to inform-owner
;  ask turtles-here with [member? breed human-types]
;  [ set own-infected-flock? TRUE]
;  ask byowners-here [ set infectious? TRUE]
;end

to set-trader-contam-time
  if contaminated? = TRUE [ set trader-contam-time trader-contam-time + 1 ]
end

to set-road-contam-time
  if pcontaminated? = TRUE [ set road-contam-time road-contam-time + 1 ]
end

to set-field-contam-time
  if pcontaminated? = TRUE [ set field-contam-time field-contam-time + 1 ]
end

to decontaminate-traders
    if trader-contam-time >= trader-contam-period
      [
        set contaminated? FALSE
        set trader-contam-time 0
      ]
end

to decontaminate-roads
  if (road-contam-time >= road-contam-period) [
    set pcontaminated? FALSE
    set road-contam-time 0
  ]
end

to decontaminate-fields
  if (field-contam-time >= field-contam-period) [
    set pcontaminated? FALSE
    set field-contam-time 0
  ]
end

to-report basic-info
  report (word
  "fcowners: " (count fcowners)
  "\neggtraders: " (count eggtraders)
  "\nrice fields: " (count patches with [patch-type = "ricefield"])
  )
end

to test-for-endsim
  if (
      (count turtles with [member? breed poultry-types and latent? ])
      + (count turtles with [member? breed poultry-types and infectious? ])
      + (count byowners with [latent? ])
      + (count byowners with [infectious? ]) 
      + (count turtles with [member? breed human-types and contaminated? ]) 
      + (count barns with [ pcontaminated? ]) 
      + (count practice-arenas with [ pcontaminated? ])
      = 0) [
    set stop-sim-reason (word "Outbreak is over " ticks " ticks.")
    set runsim? false
  ]
end


to do-plots                                                                
  set-current-plot "Contamination"
  set-current-plot-pen "Barns Near Road"
  plot count barns with [pcontaminated? = TRUE]
;  set-current-plot-pen "Rice Fields"                                     ;; These fields are contaminated now b/c of being in the road patch set
;  plot count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)] ; Look at the Contaminations table for number of fields contam
  set-current-plot-pen "Egg Traders"
  plot count eggtraders with [contaminated? = TRUE]
  set-current-plot-pen "Live Traders"
  plot count livetraders with [contaminated? = TRUE]
  
  set-current-plot "FGD Infection State"
  set-current-plot-pen "Latent Flocks"
  plot count fgds with [ latent? ]
  set-current-plot-pen "Infectious Flocks"
  plot count fgds with [ infectious? ]
  set-current-plot-pen "Recovered Flocks"
  plot count fgds with [ recovered? ]
  
  set-current-plot "Backyard Chickens Infection State"
  set-current-plot-pen "Latent Flocks"
  plot count bychickens with [ latent? ]
  set-current-plot-pen "Infectious Flocks"
  plot count bychickens with [ infectious? ]
  set-current-plot-pen "Flock Death"
  plot count bychickens with [ death? ]
  
  set-current-plot "Small Duck Flocks Infection State"
  set-current-plot-pen "Latent Flocks"
  plot count byducks with [ latent? ]
  set-current-plot-pen "Infectious Flocks"
  plot count byducks with [ infectious? ]
  set-current-plot-pen "Recovered Flocks"
  plot count byducks with [ recovered? ]
  
  set-current-plot "Farm Infection State"
  set-current-plot-pen "Latent Flocks"
  plot count farms with [ latent? ]
  set-current-plot-pen "Infectious Flocks"
  plot count farms with [ infectious? ]
  set-current-plot-pen "Flock Death/ Recovery"
  plot count farms with [ death? or recovered?]

  set-current-plot "Proportion of Flocks Affected (Post-shedding)"
  set-current-plot-pen "Backyard Flocks"
  plot ((count bychickens with [death?]) / N-BYOWNERS)
  set-current-plot-pen "Small Duck Flocks"
  plot ((count byducks with [recovered?]) / N-BYDUCKOWNERS)
  set-current-plot-pen "FGD Flocks"
  plot ((count fgds with [recovered?]) / N-FGD)
  set-current-plot-pen "Farms"
  plot ((count farms with [recovered? or death?]) / N-FARMOWNERS)

  set-current-plot "rai available"
  clear-plot
  set-current-plot-pen "rai01"
  set-plot-pen-mode 0
  ;;make cumulative sum
  let %rai reduce [lput (?2 + last ?1) ?1] fput [0] (sort [rai] of access-fields)
  let %xvals n-values (count access-fields + 1) [?]
  ;;if (last %rai < 0.5 * plot-y-max) [set-plot-y-range 0 last %rai]
  (foreach %xvals %rai [plotxy ?1 ?2])
  set-plot-y-range 0 7500

end

;;;;;;;;;;;;;;;;;;;;;;; tests ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to test-setup
  show "enter proc: test-setup"
  test-setup-patches
  test-setup-agents
  show "exit proc: test-setup"
end

to test-setup-patches
  ;;;;;;  check that setup-patches meets expectations, ow raise error


  ;; ensure that only ricefields shd have a non-empty field-state 
  ask patches [
    if (patch-type = "ricefield") and (not member? field-state ["growing" "harvested" "fallow"]) [
      __error "ricefields should have field-state"
    ]
    if (patch-type != "ricefield" and field-state != "") [
      __error "non-ricefields should not have field-state"
    ]
  ]

  ask access-fields [
    ask field-patches [
      if (field-num != [field-num] of myself)
      or (field-state != [field-state] of myself) [
        __error "problem in field setup"
      ]
    ]
  ]
end

to test-setup-agents
  ask fgds [
    if (not is-turtle? owner) [__error "problem setting owner of fgds"]
  ]

  if not (count livetraders = N-LIVETRADERS) [__error "wrong number of livetraders"]
end

to test-go
  ask fgds with [field-only?] [
    let %patch patch-here
    let %owner-patch nobody
    ask owner [set %owner-patch patch-here]
    if not (%owner-patch = %patch) [
      show (word "I'm on " %patch " but my owner is on " %owner-patch)
      __error "fgds should be tied to owner"
    ]
  ]
end



@#$#@#$#@
GRAPHICS-WINDOW
255
10
952
728
30
30
11.2623
1
10
1
1
1
0
0
0
1
-30
30
-30
30
1
1
1
days

BUTTON
5
5
65
38
NIL
Setup
NIL
1
T
OBSERVER
NIL
S
NIL
NIL

BUTTON
70
5
130
38
NIL
Go
T
1
T
OBSERVER
NIL
G
NIL
NIL

BUTTON
135
5
195
38
Go Once
go
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL

SLIDER
5
40
185
73
prop-fgd-barntofield
prop-fgd-barntofield
0
1
0.6
0.1
1
NIL
HORIZONTAL

SLIDER
5
75
185
108
num-fgd-inf
num-fgd-inf
0
5
1
1
1
flocks
HORIZONTAL

SLIDER
5
110
185
143
num-fields-contam
num-fields-contam
0
10
0
1
1
NIL
HORIZONTAL

SLIDER
5
145
185
178
num-fields-harvested
num-fields-harvested
0
40
40
1
1
NIL
HORIZONTAL

SWITCH
5
180
95
213
co-op?
co-op?
1
1
-1000

SWITCH
85
180
185
213
Influenza?
Influenza?
0
1
-1000

PLOT
5
220
247
370
Contamination
time
totals
0.0
10.0
0.0
10.0
true
true
PENS
"Barns Near Road" 1.0 0 -13345367 true
"Rice Fields" 1.0 0 -13840069 true
"Egg Traders" 1.0 0 -955883 true
"Live Traders" 1.0 0 -5825686 true

PLOT
5
375
246
525
FGD Infection State
time
totals
0.0
10.0
0.0
10.0
true
true
PENS
"Latent Flocks" 1.0 0 -10899396 true
"Infectious Flocks" 1.0 0 -2674135 true
"Recovered Flocks" 1.0 0 -5987164 true

MONITOR
960
10
1060
55
rice fields
count rice-fields
0
1
11

MONITOR
1065
10
1165
55
non-rice patches
count patches with [field-state = \"\" ]
0
1
11

MONITOR
1170
10
1320
55
Current Date
(word day-name \" of week: \" week)
0
1
11

MONITOR
960
55
1060
100
chk egg traders
count eggtraders with [ egg-type = \"chicken\"]
0
1
11

MONITOR
1065
55
1165
100
duck egg traders
count eggtraders with [egg-type = \"duck\"]
0
1
11

MONITOR
1170
55
1320
100
chk & duck egg traders
count eggtraders with [egg-type = \"duck and chicken\"]
0
1
11

PLOT
5
530
245
680
Backyard Chickens Infection State
time
totals
0.0
10.0
0.0
10.0
true
true
PENS
"Latent Flocks" 1.0 0 -10899396 true
"Infectious Flocks" 1.0 0 -2674135 true
"Flock Death" 1.0 0 -5987164 true

PLOT
955
110
1210
265
Small Duck Flocks Infection State
time
totals
0.0
10.0
0.0
10.0
true
true
PENS
"Latent Flocks" 1.0 0 -10899396 true
"Infectious Flocks" 1.0 0 -2674135 true
"Recovered Flocks" 1.0 0 -7500403 true

PLOT
955
265
1210
420
Farm Infection State
time
totals
0.0
10.0
0.0
10.0
true
true
PENS
"Latent Flocks" 1.0 0 -10899396 true
"Infectious Flocks" 1.0 0 -2674135 true
"Flock Death/ Recovery" 1.0 0 -7500403 true

PLOT
955
420
1205
575
Proportion of Flocks Affected (Post-shedding)
time
proportion
0.0
10.0
0.0
0.5
true
true
PENS
"Backyard Flocks" 1.0 0 -11221820 true
"FGD Flocks" 1.0 0 -13840069 true
"Small Duck Flocks" 1.0 0 -5825686 true
"Farms" 1.0 0 -6459832 true

PLOT
955
575
1155
725
rai available
num fields
total rai
0.0
32.0
0.0
6000.0
true
false
PENS
"rai01" 1.0 0 -16777216 true

@#$#@#$#@
WHAT IS IT?
-----------
This is an agent-based model of the subdistrict poultry sector in Central Thailand.

For this project, we conducted interviews with free-grazing duck owners, backyard poultry owners, large farm owners, poultry traders, slaughterhouse workers and egg traders in three subdistricts of Suphanburi Province, Thailand. The interviews focused on the frequency and character of poultry-related contacts, including the transport, sale and purchase of both birds and eggs. All of these aspects are reflected in the model. The agents interact on a spatially representative backdrop of a Thai subdistrict. 

The objective for modeling this system is to observe the contact frequencies and types that occur among members of the subdistrict poultry sector and hypothesize what contact types pose the greatest risk for transmission of highly pathogenic avian influenza (HPAI) H5N1. Generation of different scenarios also allow the assessment of interventions that could result in a decrease of between-flock avian influenza virus transmission risk. 


HOW IT WORKS
------------
BROWN-Roads
GREEN- Fields with growing rice
YELLOW- Fields with harvested rice
LIGHT YELLOW- Fallow fields
BLUE- Barns
RED- Fighting cock arenas
VIOLET- Markets or egg cooperative (marked with "C")
PINK- Slaughterhouses

GOLD PERSON- Backyard chicken owner, subset owns fighting cocks
Backyard characteristics: Freely roam around home yard and close to/ into road. Do not travel from home. No eggs collected/ delivered. Infrequent pickup by live poultry traders.
Backyard contacts made: FGD passing by yard on foot (direct); Infected fighting cocks returning to flock (direct); FGD by contaminated roads (indirect); Other flocks by live poultry traders (indirect); Other flocks by owner visiting (indirect)

Fighting cock characteristics: Owners go weekly to practice arena for fights, but do not bring cocks every time. Owners bring fighting cocks at rate of twice yearly to match arena.
Fighting cock contacts made: Fighting against infectious cock at practice or match (direct); Infectious birds at practice arena, owner as fomite (indirect)

WHITE DUCK- FGD flock; WHITE PERSON- FGD owner
Characteristics: Move from home to field daily. Have the potential to become infected at the rice field via theoretical interaction with wild birds. When traveling on the roads from home to field may contact, directly or indirectly, backyard poultry. Have eggs collected/ delivered.
Contacts made: Backyard poultry en route to fields (direct); Backyard poultry by contaminated roads (indirect); Other flocks by egg collectors (indirect); Other flocks by owner visiting (indirect)

GREEN PERSON- Chicken or duck farm owner
Characteristics: Large flocks of chickens or ducks kept in barns, usually with open sides and located over body of water. Used primarily for egg production.
Contacts made: Other flocks by egg collectors (indirect); Other flocks by owner visiting (indirect)

BROWN PERSON- Backyard duck owner
Characteristics: Penned ducks in small flocks of approx. 50-500 head. Do not travel from home. Eggs picked up/ delivered. Infrequent pickup by live poultry traders.
Contacts made: FGD by contaminated roads?(indirect); Other flocks by egg collectors (indirect); Other flocks by live poultry traders (indirect); Other flocks by owner visiting

CAR- Egg trader
Characteristics: Create a network of farms to go to on a certain number of trading days each week. Go to the same farms on each trading day. Bring eggs to a specific market or egg cooperative each trading day.
Contacts made: Farms where pick up eggs (contamination source); Flocks by acting as fomites, via shoes and vehicles (location to contaminate)

TRUCK- Live poultry trader
Characteristics: On a certain number of trading days each week, create a network of farms to go to. Go to the different farms on each trading day. Bring birds back to home for slaughter.
COntacts made: Farms where pick up birds (contamination source); Flocks by acting as fomites, via shoes, clothing and vehicles (location to contaminate)


HOW TO USE IT
-------------
This section could explain how to use the model, including a description of each of the items in the interface tab.


THINGS TO NOTICE
----------------
This section could give some ideas of things for the user to notice while running the model.


THINGS TO TRY
-------------
This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.


EXTENDING THE MODEL
-------------------
This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.


NETLOGO FEATURES
----------------
This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab.  It might also point out places where workarounds were needed because of missing features.


RELATED MODELS
--------------
This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.


CREDITS AND REFERENCES
----------------------
This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.
@#$#@#$#@
default
true
0
Polygon -7500403 true true 150 5 40 250 150 205 260 250

airplane
true
0
Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15

arrow
true
0
Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150

backyard
true
0
Circle -955883 true false 73 101 64
Rectangle -955883 true false 105 137 165 240
Rectangle -2674135 true false 84 91 127 112
Circle -1184463 true false 92 205 38
Circle -1184463 true false 138 205 40
Circle -11221820 true false 91 116 14
Polygon -1184463 true false 64 120 45 135 75 150 75 120

bird side
false
0
Polygon -7500403 true true 0 120 45 90 75 90 105 120 150 120 240 135 285 120 285 135 300 150 240 150 195 165 255 195 210 195 150 210 90 195 60 180 45 135
Circle -16777216 true false 38 98 14

box
false
0
Polygon -7500403 true true 150 285 285 225 285 75 150 135
Polygon -7500403 true true 150 135 15 75 150 15 285 75
Polygon -7500403 true true 15 75 15 225 150 285 150 135
Line -16777216 false 150 285 150 135
Line -16777216 false 150 135 15 75
Line -16777216 false 150 135 285 75

bug
true
0
Circle -7500403 true true 96 182 108
Circle -7500403 true true 110 127 80
Circle -7500403 true true 110 75 80
Line -7500403 true 150 100 80 30
Line -7500403 true 150 100 220 30

butterfly
true
0
Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240
Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240
Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163
Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165
Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225
Circle -16777216 true false 135 90 30
Line -16777216 false 150 105 195 60
Line -16777216 false 150 105 105 60

car
false
0
Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180
Circle -16777216 true false 180 180 90
Circle -16777216 true false 30 180 90
Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89
Circle -7500403 true true 47 195 58
Circle -7500403 true true 195 195 58

circle
false
0
Circle -7500403 true true 0 0 300

circle 2
false
0
Circle -7500403 true true 0 0 300
Circle -16777216 true false 30 30 240

cow
false
0
Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167
Polygon -7500403 true true 73 210 86 251 62 249 48 208
Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123

cylinder
false
0
Circle -7500403 true true 0 0 300

dot
false
0
Circle -7500403 true true 90 90 120

duck
true
3
Circle -6459832 true true 150 45 60
Circle -6459832 true true 74 74 122
Rectangle -955883 true false 150 45 165 60
Line -955883 false 75 150 60 150
Line -955883 false 75 120 60 120
Line -955883 false 90 105 60 105
Line -955883 false 90 165 60 165
Line -955883 false 60 105 60 120
Line -955883 false 60 150 60 165
Rectangle -955883 true false 60 105 75 120
Rectangle -955883 true false 75 105 90 120
Rectangle -955883 true false 60 150 90 165
Rectangle -11221820 true false 180 60 195 75

face happy
false
0
Circle -7500403 true true 8 8 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240

face neutral
false
0
Circle -7500403 true true 8 7 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Rectangle -16777216 true false 60 195 240 225

face sad
false
0
Circle -7500403 true true 8 8 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183

farm
true
0
Circle -1184463 true false 73 101 64
Rectangle -1184463 true false 105 137 165 240
Rectangle -2674135 true false 84 91 127 112
Circle -955883 true false 92 205 38
Circle -955883 true false 138 205 40
Circle -11221820 true false 91 116 14
Polygon -955883 true false 64 120 45 135 75 150 75 120

fish
false
0
Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166
Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165
Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60
Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166
Circle -16777216 true false 215 106 30

flag
false
0
Rectangle -7500403 true true 60 15 75 300
Polygon -7500403 true true 90 150 270 90 90 30
Line -7500403 true 75 135 90 135
Line -7500403 true 75 45 90 45

flower
false
0
Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135
Circle -7500403 true true 85 132 38
Circle -7500403 true true 130 147 38
Circle -7500403 true true 192 85 38
Circle -7500403 true true 85 40 38
Circle -7500403 true true 177 40 38
Circle -7500403 true true 177 132 38
Circle -7500403 true true 70 85 38
Circle -7500403 true true 130 25 38
Circle -7500403 true true 96 51 108
Circle -16777216 true false 113 68 74
Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218
Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240

house
false
0
Rectangle -7500403 true true 45 120 255 285
Rectangle -16777216 true false 120 210 180 285
Polygon -7500403 true true 15 120 150 15 285 120
Line -16777216 false 30 120 270 120

leaf
false
0
Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195
Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195

line
true
0
Line -7500403 true 150 0 150 300

line half
true
0
Line -7500403 true 150 0 150 150

pentagon
false
0
Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120

person
false
0
Circle -7500403 true true 110 5 80
Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90
Rectangle -7500403 true true 127 79 172 94
Polygon -7500403 true true 195 90 240 150 225 180 165 105
Polygon -7500403 true true 105 90 60 150 75 180 135 105

plant
false
0
Rectangle -7500403 true true 135 90 165 300
Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285
Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285
Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210
Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135
Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135
Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60
Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90

sheep
false
0
Rectangle -7500403 true true 151 225 180 285
Rectangle -7500403 true true 47 225 75 285
Rectangle -7500403 true true 15 75 210 225
Circle -7500403 true true 135 75 150
Circle -16777216 true false 165 76 116

square
false
0
Rectangle -7500403 true true 30 30 270 270

square 2
false
0
Rectangle -7500403 true true 30 30 270 270
Rectangle -16777216 true false 60 60 240 240

star
false
0
Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108

target
false
0
Circle -7500403 true true 0 0 300
Circle -16777216 true false 30 30 240
Circle -7500403 true true 60 60 180
Circle -16777216 true false 90 90 120
Circle -7500403 true true 120 120 60

tree
false
0
Circle -7500403 true true 118 3 94
Rectangle -6459832 true false 120 195 180 300
Circle -7500403 true true 65 21 108
Circle -7500403 true true 116 41 127
Circle -7500403 true true 45 90 120
Circle -7500403 true true 104 74 152

triangle
false
0
Polygon -7500403 true true 150 30 15 255 285 255

triangle 2
false
0
Polygon -7500403 true true 150 30 15 255 285 255
Polygon -16777216 true false 151 99 225 223 75 224

truck
false
0
Rectangle -7500403 true true 4 45 195 187
Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194
Rectangle -1 true false 195 60 195 105
Polygon -16777216 true false 238 112 252 141 219 141 218 112
Circle -16777216 true false 234 174 42
Rectangle -7500403 true true 181 185 214 194
Circle -16777216 true false 144 174 42
Circle -16777216 true false 24 174 42
Circle -7500403 false true 24 174 42
Circle -7500403 false true 144 174 42
Circle -7500403 false true 234 174 42

turtle
true
0
Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210
Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105
Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105
Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87
Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210
Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99

wheel
false
0
Circle -7500403 true true 3 3 294
Circle -16777216 true false 30 30 240
Line -7500403 true 150 285 150 15
Line -7500403 true 15 150 285 150
Circle -7500403 true true 120 120 60
Line -7500403 true 216 40 79 269
Line -7500403 true 40 84 269 221
Line -7500403 true 40 216 269 79
Line -7500403 true 84 40 221 269

x
false
0
Polygon -7500403 true true 270 75 225 30 30 225 75 270
Polygon -7500403 true true 30 75 75 30 270 225 225 270

@#$#@#$#@
NetLogo 4.1.2
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
<experiments>
  <experiment name="Baseline Model" repetitions="100" runMetricsEveryStep="true">
    <setup>setup</setup>
    <go>go</go>
    <final>export-transmissions-and-contaminations</final>
    <metric>table:to-list transmissions</metric>
    <metric>table:to-list contaminations</metric>
    <metric>table:to-list days-on-field</metric>
    <metric>count barns with [pcontaminated? = TRUE]</metric>
    <metric>count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)]</metric>
    <metric>count fgds with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count fgds with [ latent? ]</metric>
    <metric>count fgds with [ infectious? ]</metric>
    <metric>count fgds with [ recovered? ]</metric>
    <metric>count bychickens with [not (latent?) and not (infectious?) and not (death?)]</metric>
    <metric>count bychickens with [ latent? ]</metric>
    <metric>count bychickens with [ infectious? ]</metric>
    <metric>count bychickens with [ death? ]</metric>
    <metric>count byducks with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count byducks with [ latent? ]</metric>
    <metric>count byducks with [ infectious? ]</metric>
    <metric>count byducks with [ recovered? ]</metric>
    <metric>count farms with [not (latent?) and not (infectious?) and not (death?) and not (recovered?)]</metric>
    <metric>count farms with [ latent? ]</metric>
    <metric>count farms with [ infectious? ]</metric>
    <metric>count farms with [ death? or recovered?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and latent?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and infectious?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and (recovered?)]</metric>
    <metric>count byowners with [ latent? ]</metric>
    <metric>count byowners with [ infectious? ]</metric>
    <metric>count byowners with [ recovered?]</metric>
    <metric>count eggtraders</metric>
    <enumeratedValueSet variable="road-infect-pen-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="road-infect-byc-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="from-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="to-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="flock-eggtrader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="eggtrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="live-trader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="livetrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-chicken">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-duck">
      <value value="0"/>
    </enumeratedValueSet>
  </experiment>
  <experiment name="Visitor Infect Prob" repetitions="100" runMetricsEveryStep="true">
    <setup>setup</setup>
    <go>go</go>
    <final>export-transmissions-and-contaminations</final>
    <metric>table:to-list transmissions</metric>
    <metric>table:to-list contaminations</metric>
    <metric>count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)]</metric>
    <metric>count fgds with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count fgds with [ latent? ]</metric>
    <metric>count fgds with [ infectious? ]</metric>
    <metric>count fgds with [ recovered? ]</metric>
    <metric>count bychickens with [not (latent?) and not (infectious?) and not (death?)]</metric>
    <metric>count bychickens with [ latent? ]</metric>
    <metric>count bychickens with [ infectious? ]</metric>
    <metric>count bychickens with [ death? ]</metric>
    <metric>count byducks with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count byducks with [ latent? ]</metric>
    <metric>count byducks with [ infectious? ]</metric>
    <metric>count byducks with [ recovered? ]</metric>
    <metric>count farms with [not (latent?) and not (infectious?) and not (death?) and not (recovered?)]</metric>
    <metric>count farms with [ latent? ]</metric>
    <metric>count farms with [ infectious? ]</metric>
    <metric>count farms with [ death? or recovered?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and latent?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and infectious?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and (recovered?)]</metric>
    <metric>count byowners with [ latent? ]</metric>
    <metric>count byowners with [ infectious? ]</metric>
    <metric>count byowners with [ recovered?]</metric>
    <metric>count eggtraders</metric>
    <enumeratedValueSet variable="road-infect-pen-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="road-infect-byc-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="from-visit-infect-prob">
      <value value="98"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="to-visit-infect-prob">
      <value value="100"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="flock-eggtrader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="eggtrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="live-trader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="livetrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-chicken">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-duck">
      <value value="0"/>
    </enumeratedValueSet>
  </experiment>
  <experiment name="FGD Field Barn" repetitions="100" runMetricsEveryStep="true">
    <setup>setup</setup>
    <go>go</go>
    <final>export-transmissions-and-contaminations</final>
    <metric>table:to-list transmissions</metric>
    <metric>table:to-list contaminations</metric>
    <metric>table:to-list days-on-field</metric>
    <metric>count barns with [pcontaminated? = TRUE]</metric>
    <metric>count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)]</metric>
    <metric>count fgds with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count fgds with [ latent? ]</metric>
    <metric>count fgds with [ infectious? ]</metric>
    <metric>count fgds with [ recovered? ]</metric>
    <metric>count bychickens with [not (latent?) and not (infectious?) and not (death?)]</metric>
    <metric>count bychickens with [ latent? ]</metric>
    <metric>count bychickens with [ infectious? ]</metric>
    <metric>count bychickens with [ death? ]</metric>
    <metric>count byducks with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count byducks with [ latent? ]</metric>
    <metric>count byducks with [ infectious? ]</metric>
    <metric>count byducks with [ recovered? ]</metric>
    <metric>count farms with [not (latent?) and not (infectious?) and not (death?) and not (recovered?)]</metric>
    <metric>count farms with [ latent? ]</metric>
    <metric>count farms with [ infectious? ]</metric>
    <metric>count farms with [ death? or recovered?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and latent?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and infectious?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and (recovered?)]</metric>
    <metric>count byowners with [ latent? ]</metric>
    <metric>count byowners with [ infectious? ]</metric>
    <metric>count byowners with [ recovered?]</metric>
    <metric>count eggtraders</metric>
    <enumeratedValueSet variable="road-infect-pen-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="road-infect-byc-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="from-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="to-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="flock-eggtrader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="eggtrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="live-trader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="livetrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-chicken">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-duck">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="prop-fgd-barntofield">
      <value value="0.6"/>
    </enumeratedValueSet>
  </experiment>
  <experiment name="Eggtrader links" repetitions="100" runMetricsEveryStep="true">
    <setup>setup</setup>
    <go>go</go>
    <final>export-transmissions-and-contaminations</final>
    <metric>table:to-list transmissions</metric>
    <metric>table:to-list contaminations</metric>
    <metric>count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)]</metric>
    <metric>count fgds with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count fgds with [ latent? ]</metric>
    <metric>count fgds with [ infectious? ]</metric>
    <metric>count fgds with [ recovered? ]</metric>
    <metric>count bychickens with [not (latent?) and not (infectious?) and not (death?)]</metric>
    <metric>count bychickens with [ latent? ]</metric>
    <metric>count bychickens with [ infectious? ]</metric>
    <metric>count bychickens with [ death? ]</metric>
    <metric>count byducks with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count byducks with [ latent? ]</metric>
    <metric>count byducks with [ infectious? ]</metric>
    <metric>count byducks with [ recovered? ]</metric>
    <metric>count farms with [not (latent?) and not (infectious?) and not (death?) and not (recovered?)]</metric>
    <metric>count farms with [ latent? ]</metric>
    <metric>count farms with [ infectious? ]</metric>
    <metric>count farms with [ death? or recovered?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and latent?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and infectious?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and (recovered?)]</metric>
    <metric>count byowners with [ latent? ]</metric>
    <metric>count byowners with [ infectious? ]</metric>
    <metric>count byowners with [ recovered?]</metric>
    <metric>count eggtraders</metric>
    <enumeratedValueSet variable="road-infect-pen-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="road-infect-byc-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="from-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="to-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="flock-eggtrader-contam-prob">
      <value value="88"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="eggtrader-flock-infect-prob">
      <value value="85"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="live-trader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="livetrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-chicken">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-duck">
      <value value="0"/>
    </enumeratedValueSet>
  </experiment>
  <experiment name="Duck Shedding" repetitions="100" runMetricsEveryStep="true">
    <setup>setup</setup>
    <go>go</go>
    <final>export-transmissions-and-contaminations</final>
    <metric>table:to-list transmissions</metric>
    <metric>table:to-list contaminations</metric>
    <metric>count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)]</metric>
    <metric>count fgds with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count fgds with [ latent? ]</metric>
    <metric>count fgds with [ infectious? ]</metric>
    <metric>count fgds with [ recovered? ]</metric>
    <metric>count bychickens with [not (latent?) and not (infectious?) and not (death?)]</metric>
    <metric>count bychickens with [ latent? ]</metric>
    <metric>count bychickens with [ infectious? ]</metric>
    <metric>count bychickens with [ death? ]</metric>
    <metric>count byducks with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count byducks with [ latent? ]</metric>
    <metric>count byducks with [ infectious? ]</metric>
    <metric>count byducks with [ recovered? ]</metric>
    <metric>count farms with [not (latent?) and not (infectious?) and not (death?) and not (recovered?)]</metric>
    <metric>count farms with [ latent? ]</metric>
    <metric>count farms with [ infectious? ]</metric>
    <metric>count farms with [ death? or recovered?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and latent?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and infectious?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and (recovered?)]</metric>
    <metric>count byowners with [ latent? ]</metric>
    <metric>count byowners with [ infectious? ]</metric>
    <metric>count byowners with [ recovered?]</metric>
    <metric>count eggtraders</metric>
    <enumeratedValueSet variable="road-infect-pen-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="road-infect-byc-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="from-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="to-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="flock-eggtrader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="eggtrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="live-trader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="livetrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-chicken">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-duck">
      <value value="0"/>
    </enumeratedValueSet>
  </experiment>
  <experiment name="Chicken Shedding" repetitions="100" runMetricsEveryStep="true">
    <setup>setup</setup>
    <go>go</go>
    <final>export-transmissions-and-contaminations</final>
    <metric>table:to-list transmissions</metric>
    <metric>table:to-list contaminations</metric>
    <metric>count barns with [pcontaminated? = TRUE]</metric>
    <metric>count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)]</metric>
    <metric>count fgds with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count fgds with [ latent? ]</metric>
    <metric>count fgds with [ infectious? ]</metric>
    <metric>count fgds with [ recovered? ]</metric>
    <metric>count bychickens with [not (latent?) and not (infectious?) and not (death?)]</metric>
    <metric>count bychickens with [ latent? ]</metric>
    <metric>count bychickens with [ infectious? ]</metric>
    <metric>count bychickens with [ death? ]</metric>
    <metric>count byducks with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count byducks with [ latent? ]</metric>
    <metric>count byducks with [ infectious? ]</metric>
    <metric>count byducks with [ recovered? ]</metric>
    <metric>count farms with [not (latent?) and not (infectious?) and not (death?) and not (recovered?)]</metric>
    <metric>count farms with [ latent? ]</metric>
    <metric>count farms with [ infectious? ]</metric>
    <metric>count farms with [ death? or recovered?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and latent?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and infectious?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and (recovered?)]</metric>
    <metric>count byowners with [ latent? ]</metric>
    <metric>count byowners with [ infectious? ]</metric>
    <metric>count byowners with [ recovered?]</metric>
    <metric>count eggtraders</metric>
    <enumeratedValueSet variable="shedding-period-chicken">
      <value value="1"/>
      <value value="5"/>
    </enumeratedValueSet>
  </experiment>
  <experiment name="Road BYC Inf" repetitions="100" runMetricsEveryStep="true">
    <setup>setup</setup>
    <go>go</go>
    <final>export-transmissions-and-contaminations</final>
    <metric>table:to-list transmissions</metric>
    <metric>table:to-list contaminations</metric>
    <metric>count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)]</metric>
    <metric>count fgds with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count fgds with [ latent? ]</metric>
    <metric>count fgds with [ infectious? ]</metric>
    <metric>count fgds with [ recovered? ]</metric>
    <metric>count bychickens with [not (latent?) and not (infectious?) and not (death?)]</metric>
    <metric>count bychickens with [ latent? ]</metric>
    <metric>count bychickens with [ infectious? ]</metric>
    <metric>count bychickens with [ death? ]</metric>
    <metric>count byducks with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count byducks with [ latent? ]</metric>
    <metric>count byducks with [ infectious? ]</metric>
    <metric>count byducks with [ recovered? ]</metric>
    <metric>count farms with [not (latent?) and not (infectious?) and not (death?) and not (recovered?)]</metric>
    <metric>count farms with [ latent? ]</metric>
    <metric>count farms with [ infectious? ]</metric>
    <metric>count farms with [ death? or recovered?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and latent?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and infectious?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and (recovered?)]</metric>
    <metric>count byowners with [ latent? ]</metric>
    <metric>count byowners with [ infectious? ]</metric>
    <metric>count byowners with [ recovered?]</metric>
    <metric>count eggtraders</metric>
    <enumeratedValueSet variable="road-infect-pen-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="road-infect-byc-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="from-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="to-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="flock-eggtrader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="eggtrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="live-trader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="livetrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-chicken">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-duck">
      <value value="0"/>
    </enumeratedValueSet>
  </experiment>
  <experiment name="RoadPEN Prob" repetitions="100" runMetricsEveryStep="true">
    <setup>setup</setup>
    <go>go</go>
    <final>export-transmissions-and-contaminations</final>
    <metric>table:to-list transmissions</metric>
    <metric>table:to-list contaminations</metric>
    <metric>count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)]</metric>
    <metric>count fgds with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count fgds with [ latent? ]</metric>
    <metric>count fgds with [ infectious? ]</metric>
    <metric>count fgds with [ recovered? ]</metric>
    <metric>count bychickens with [not (latent?) and not (infectious?) and not (death?)]</metric>
    <metric>count bychickens with [ latent? ]</metric>
    <metric>count bychickens with [ infectious? ]</metric>
    <metric>count bychickens with [ death? ]</metric>
    <metric>count byducks with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count byducks with [ latent? ]</metric>
    <metric>count byducks with [ infectious? ]</metric>
    <metric>count byducks with [ recovered? ]</metric>
    <metric>count farms with [not (latent?) and not (infectious?) and not (death?) and not (recovered?)]</metric>
    <metric>count farms with [ latent? ]</metric>
    <metric>count farms with [ infectious? ]</metric>
    <metric>count farms with [ death? or recovered?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and latent?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and infectious?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and (recovered?)]</metric>
    <metric>count byowners with [ latent? ]</metric>
    <metric>count byowners with [ infectious? ]</metric>
    <metric>count byowners with [ recovered?]</metric>
    <metric>count eggtraders</metric>
    <enumeratedValueSet variable="road-infect-pen-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="road-infect-byc-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="from-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="to-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="flock-eggtrader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="eggtrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="live-trader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="livetrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-chicken">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-duck">
      <value value="0"/>
    </enumeratedValueSet>
  </experiment>
  <experiment name="Initial Infection" repetitions="100" runMetricsEveryStep="true">
    <setup>setup</setup>
    <go>go</go>
    <final>export-transmissions-and-contaminations</final>
    <metric>table:to-list transmissions</metric>
    <metric>table:to-list contaminations</metric>
    <metric>table:to-list days-on-field</metric>
    <metric>count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)]</metric>
    <metric>count fgds with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count fgds with [ latent? ]</metric>
    <metric>count fgds with [ infectious? ]</metric>
    <metric>count fgds with [ recovered? ]</metric>
    <metric>count bychickens with [not (latent?) and not (infectious?) and not (death?)]</metric>
    <metric>count bychickens with [ latent? ]</metric>
    <metric>count bychickens with [ infectious? ]</metric>
    <metric>count bychickens with [ death? ]</metric>
    <metric>count byducks with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count byducks with [ latent? ]</metric>
    <metric>count byducks with [ infectious? ]</metric>
    <metric>count byducks with [ recovered? ]</metric>
    <metric>count farms with [not (latent?) and not (infectious?) and not (death?) and not (recovered?)]</metric>
    <metric>count farms with [ latent? ]</metric>
    <metric>count farms with [ infectious? ]</metric>
    <metric>count farms with [ death? or recovered?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and latent?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and infectious?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and (recovered?)]</metric>
    <metric>count byowners with [ latent? ]</metric>
    <metric>count byowners with [ infectious? ]</metric>
    <metric>count byowners with [ recovered?]</metric>
    <metric>count eggtraders</metric>
    <enumeratedValueSet variable="road-infect-pen-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="road-infect-byc-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="from-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="to-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="flock-eggtrader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="eggtrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="live-trader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="livetrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-chicken">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-duck">
      <value value="0"/>
    </enumeratedValueSet>
  </experiment>
  <experiment name="Eggtrader Contam Inf" repetitions="100" runMetricsEveryStep="true">
    <setup>setup</setup>
    <go>go</go>
    <final>export-transmissions-and-contaminations</final>
    <metric>table:to-list transmissions</metric>
    <metric>table:to-list contaminations</metric>
    <metric>count barns with [pcontaminated? = TRUE]</metric>
    <metric>count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)]</metric>
    <metric>count fgds with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count fgds with [ latent? ]</metric>
    <metric>count fgds with [ infectious? ]</metric>
    <metric>count fgds with [ recovered? ]</metric>
    <metric>count bychickens with [not (latent?) and not (infectious?) and not (death?)]</metric>
    <metric>count bychickens with [ latent? ]</metric>
    <metric>count bychickens with [ infectious? ]</metric>
    <metric>count bychickens with [ death? ]</metric>
    <metric>count byducks with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count byducks with [ latent? ]</metric>
    <metric>count byducks with [ infectious? ]</metric>
    <metric>count byducks with [ recovered? ]</metric>
    <metric>count farms with [not (latent?) and not (infectious?) and not (death?) and not (recovered?)]</metric>
    <metric>count farms with [ latent? ]</metric>
    <metric>count farms with [ infectious? ]</metric>
    <metric>count farms with [ death? or recovered?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and latent?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and infectious?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and (recovered?)]</metric>
    <metric>count byowners with [ latent? ]</metric>
    <metric>count byowners with [ infectious? ]</metric>
    <metric>count byowners with [ recovered?]</metric>
    <metric>count eggtraders</metric>
    <enumeratedValueSet variable="road-infect-pen-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="road-infect-byc-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="from-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="to-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="flock-eggtrader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="eggtrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="live-trader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="livetrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-chicken">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-duck">
      <value value="0"/>
    </enumeratedValueSet>
  </experiment>
  <experiment name="Livetrader Contam Inf" repetitions="100" runMetricsEveryStep="true">
    <setup>setup</setup>
    <go>go</go>
    <final>export-transmissions-and-contaminations</final>
    <metric>table:to-list transmissions</metric>
    <metric>table:to-list contaminations</metric>
    <metric>count barns with [pcontaminated? = TRUE]</metric>
    <metric>count rice-fields with [ (field-state = "harvested") and (pcontaminated? = TRUE)]</metric>
    <metric>count fgds with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count fgds with [ latent? ]</metric>
    <metric>count fgds with [ infectious? ]</metric>
    <metric>count fgds with [ recovered? ]</metric>
    <metric>count bychickens with [not (latent?) and not (infectious?) and not (death?)]</metric>
    <metric>count bychickens with [ latent? ]</metric>
    <metric>count bychickens with [ infectious? ]</metric>
    <metric>count bychickens with [ death? ]</metric>
    <metric>count byducks with [not (latent?) and not (infectious?) and not (recovered?)]</metric>
    <metric>count byducks with [ latent? ]</metric>
    <metric>count byducks with [ infectious? ]</metric>
    <metric>count byducks with [ recovered? ]</metric>
    <metric>count farms with [not (latent?) and not (infectious?) and not (death?) and not (recovered?)]</metric>
    <metric>count farms with [ latent? ]</metric>
    <metric>count farms with [ infectious? ]</metric>
    <metric>count farms with [ death? or recovered?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and latent?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and infectious?]</metric>
    <metric>count turtles with [(member? breed poultry-types) and (recovered?)]</metric>
    <metric>count byowners with [ latent? ]</metric>
    <metric>count byowners with [ infectious? ]</metric>
    <metric>count byowners with [ recovered?]</metric>
    <metric>count eggtraders</metric>
    <enumeratedValueSet variable="road-infect-pen-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="road-infect-byc-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="from-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="to-visit-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="flock-eggtrader-contam-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="eggtrader-flock-infect-prob">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="live-trader-contam-prob">
      <value value="95"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="livetrader-flock-infect-prob">
      <value value="92"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-chicken">
      <value value="0"/>
    </enumeratedValueSet>
    <enumeratedValueSet variable="shedding-period-duck">
      <value value="0"/>
    </enumeratedValueSet>
  </experiment>
</experiments>
@#$#@#$#@
@#$#@#$#@
default
0.0
-0.2 0 1.0 0.0
0.0 1 1.0 0.0
0.2 0 1.0 0.0
link direction
true
0
Line -7500403 true 150 150 90 180
Line -7500403 true 150 150 210 180

@#$#@#$#@
1
@#$#@#$#@
